//妹子when???
#include<bits/stdc++.h>
#define pb push_back
#define pc putchar
#define fi first
#define se second
#define eb emplace_back
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define mt make_tuple
using namespace std;
template<class T>void read(T&x){
	char c=getchar();bool f=0;x=0;
	for(;!isdigit(c);c=getchar())if(c=='-')f=1;
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
	if(f)x=-x;
}
template<class T,class ...Arg>void read(T&x,Arg&...arg){read(x);read(arg...);}
template<class T>void write(T x){
	if(x<0)x=-x,pc('-');
	if(x>=10)write(x/10);
	pc(x%10+'0');
}
template<class T,class ...Arg>void write(T x,Arg ...arg){write(x);pc(' ');write(arg...);}
template<class ...Arg>void writeln(Arg ...arg){write(arg...);pc('\n');}
const int mod=998244353;
struct mint{
	int x;mint(int o=0){x=o;}
	mint&operator+=(mint b){return(x+=b.x)%=mod,*this;}
	mint&operator-=(mint b){return(x-=b.x)%=mod,*this;}
	mint&operator*=(mint b){return(x=1ll*x*b.x%mod),*this;}
	friend mint operator+(mint a,mint b){return a+=b;}
	friend mint operator-(mint a,mint b){return a-=b;}
	friend mint operator*(mint a,mint b){return a*=b;}
};
const int N=1e3+10;
int T,id,n,m,c,f;
char s[N][N];
int R[N][N],D[N][N];
mint sum[N][N];
void solve(){
	memset(R,0,sizeof R);memset(D,0,sizeof D);memset(sum,0,sizeof sum);
	read(n,m,c,f);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)s[i][j]-='0';
	for(int i=n;i>=1;i--)for(int j=1;j<=m;j++)
		if(!s[i][j])D[i][j]=D[i+1][j]+1;
	for(int i=1;i<=n;i++)for(int j=m;j>=1;j--)
		if(!s[i][j])R[i][j]=R[i][j+1]+1;
	mint C=0,F=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(!s[i][j]){
		sum[i][j]=sum[i-1][j]+R[i][j]-1;
		if(i>2&&!s[i-1][j]){
			C+=sum[i-2][j]*(R[i][j]-1);
			F+=sum[i-2][j]*(R[i][j]-1)*(D[i][j]-1);
		}
	}
	C*=c,F*=f;
	writeln(C.x,F.x);
}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	read(T,id);
	while(T--)solve();
	return 0;
}
