#include<bits/stdc++.h>
using namespace std;
const int N=1010;
const int mod=998244353;
inline int read(){
	int f=1,w=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')	f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		w=(w<<1)+(w<<3)+(c^48);
		c=getchar();
	}
	return f*w;
}
int T,id;
int n,m,c,f;
int a[N][N];
int ans=0;
void search(int x,int y,int xx,int yy){
	int cnt1=0,cnt2=0;
	for(int i=y+1;i<=m;i++){
		if(!a[x][i])	cnt1++;
		else	break;
	}
	for(int i=yy+1;i<=m;i++){
		if(!a[xx][i])	cnt2++;
		else	break;
	}
//	cout<<cnt1<<" "<<cnt2<<endl;
	int res=cnt1*cnt2;
	ans+=res;
	ans%=mod;
}
void init(){
	for(int i=1;i<=1000;i++){
		for(int j=1;j<=1000;j++){
			a[i][j]=1;
		}
	}
}
int anss;
void work(int x,int y,int xx,int yy){
	int cnt1=0;
	int cnt2=0;
	for(int i=y+1;i<=m;i++){
		if(!a[x][i])	cnt1++;
		else	break;
	}
	for(int i=yy+1;i<=m;i++){
		if(!a[xx][i])	cnt2++;
		else	break;
	}
	for(int i=xx+1;i<=n;i++){
		if(!a[i][y]){
			int res=cnt1*cnt2;
			anss+=res;
			anss%=mod;
		}else{
			break;
		}
	}
}
string s;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read();
	id=read();
	while(T--){
		ans=0;
		anss=0;
		init();
		n=read();
		m=read();
		c=read();
		f=read();
		if(c==0&&f==0){
			cout<<0<<" "<<0<<endl;
			continue;
		}
		for(int i=1;i<=n;i++){
			cin>>s;
			for(int j=0;j<m;j++){
				if(s[j]=='0')	a[i][j+1]=0;
				else	a[i][j+1]=1;
			}
		}
		for(int i=1;i<=n-2;i++){
			for(int j=1;j<=m-1;j++){
				if(!a[i+1][j]&&!a[i][j+1]&&!a[i][j]){
					//cout<<i<<endl;
					for(int k=i+2;k<=n;k++){
						if(!a[k][j])
							search(i,j,k,j);
						else	
							break;
					}
				}
			}
		}
		if(c==0)	cout<<0<<" ";
		else	cout<<ans%mod<<" ";
		for(int i=1;i<=n-3;i++){
			for(int j=1;j<m;j++){
				if(!a[i+1][j]&&!a[i][j+1]&&!a[i][j]){
					for(int k=i+2;k<n;k++){
						if(!a[k][j])
							work(i,j,k,j);
						else	
							break;
					}
				}
			}
		}
		if(f==0)	cout<<0<<endl;
		else	cout<<anss%mod<<endl;
	}	
	return 0;
}