#include<bits/stdc++.h>
#define nm 2005
using namespace std;
void read(long long &n){
	char ch=getchar();
	long long k=0,f=1;
	while(ch<'0' or ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0' and ch<='9'){
		k=k*10+ch-'0';
		ch=getchar();
	}
	n=f*k;
}
const long long p=998244353;
char s[nm][nm];
long long ans1,ans2,b,c,d,e,f,g[nm][nm],h[nm][nm],x,y,T,id,hs[nm][nm];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	read(T);
	read(id);
	while(T--){
	memset(h,0,sizeof(h));
	memset(g,0,sizeof(g));
	memset(hs,0,sizeof(hs));
	read(b);
	read(c);
	read(x);
	read(y);
	ans1=ans2=0;
	for(int i=1;i<=b;i++){
			cin>>s[i]+1;
	}
	for(int i=1;i<=b;i++){
		h[i][c+1]=0;
		for(int j=c;j>=1;j--){
			if(s[i][j]=='1')h[i][j]=0;
			else h[i][j]=h[i][j+1]+1;
			h[i][j]%=p;
		}
	}
	for(int j=1;j<=c;j++){
		for(int i=1;i<=b;i++){
			if(s[i][j]=='1')g[i][j]=0;
			else g[i][j]=g[i-1][j]+h[i][j]-1;
			g[i][j]%=p;
		}
	}
	for(int j=1;j<=c;j++){
		for(int i=3;i<=b;i++){
			if(s[i][j]=='0' and s[i-1][j]=='0'){
			ans1=ans1+(h[i][j]-1)*(g[i-2][j]);
			ans1%=p;	
			}
		}
	}
	for(int i=3;i<=b;i++){
		for(int j=1;j<=c;j++){
			if(s[i][j]=='1' or s[i-1][j]=='1')hs[i][j]=0;
			else{
			hs[i][j]=hs[i-1][j]+(h[i][j]-1)*g[i-2][j];
			}
			hs[i][j]%=p;
		}
	}
	for(int i=4;i<=b;i++){
		for(int j=1;j<=c;j++){
			if(s[i][j]=='0'){
				ans2=ans2+hs[i-1][j];
				ans2%=p;
			}
		}
	}
	ans1=ans1*x%p;
	ans2=ans2*y%p;
		printf("%lld %lld",ans1,ans2);
		putchar('\n');
	}
	return 0;
}