#include <bits/stdc++.h>
using namespace std;
string s;
int t,id;
int n,m,c,f;
int a[1005][1005];

void get_vc(){
	if (c==0) cout<<0<<" ";
	else{
		int vc=0;
		int nn=n-3,mm=m-2;
		for (int i=0;i<=nn;++i)
			for (int j=0;j<=mm;++j){
				if (a[i][j] || a[i+1][j]) continue;
				for (int k=i+2;k<n;++k){
					int num=0;
					if (a[k][j]) break;
					if (!(a[i][j+1]+a[k][j+1])){
						int top=1,end=1;	
						for (int jj=j+2;!a[i][jj] && jj<m;jj++) top++;
						for (int jj=j+2;!a[k][jj] && jj<m;jj++) end++;
						vc+=(top*end)%998244353;
					} 
				}
			}
		cout<<vc<<" ";
	}
}

void get_vf(){
	if (f==0) cout<<0<<endl;
	else{
		int vf=0;
		int nn=n-4,mm=m-2;
		for (int i=0;i<=nn;++i)
			for (int j=0;j<=mm;++j){
				if (a[i][j] || a[i+1][j]) continue;
				for (int k=i+2;k<n-1;++k){
					int num=0;
					if (a[k][j]) break;
					if (!(a[i][j+1]+a[k][j+1])){
						int top=1,end=1;	
						for (int jj=j+2;!a[i][jj] && jj<m;jj++) top++;
						for (int jj=j+2;!a[k][jj] && jj<m;jj++) end++;
						int cnt=0;
						for (int p=k+1;p<=n-1 && !a[p][j];++p) cnt++;
						vf+=(top*end*cnt)%998244353;
					} 
				}
			}
		cout<<vf<<endl;
	}
}

int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>t>>id;
	while (t--){
		cin>>n>>m>>c>>f;
		memset(a,0,sizeof(a));
		for (int i=0;i<n;++i){
			cin>>s;
			for (int j=0;j<m;++j)
				if (s[j]=='1') a[i][j]++;
		}
		get_vc();
		get_vf();
	}
	return 0;
} 

