#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mo=998244353;
int T,id,n,m,cx,fx,awa;
char a[1005][1005];
LL hang(int h,int l){
	LL asd=0;
	for(int i=h;i<=n;i++){
		if(a[i][l]=='0')asd++;
		if(a[i][l]=='1')break;
	}
	return asd;
}
LL lie(int h,int l){
	LL asd=0;
	for(int i=l;i<=m;i++){
		if(a[h][i]=='0')asd++;
		if(a[h][i]=='1')break;
	}
	return asd;
}
LL Vc(int c,int h){
	LL ansc=0;
	if(c==0||h>n)return 0;
	for(int i=1;i<=m;i++){
		LL ch=hang(h,i),cl=0;
		LL de=lie(h,i)-1;
		if(de>0){
			for(int j=h+2;j<=h+ch-1;j++)cl+=lie(j,i)-1;
			ansc=(ansc+(cl*de)%mo)%mo;
		}
	}
	ansc+=Vc(c,h+1);
	return ansc;
}
LL Vf(int f,int h){
	LL ansf=0;
	if(f==0||h>=n)return 0;
	for(int i=1;i<=m;i++){
		LL fh=hang(h,i),fl=0,de=lie(h,i)-1;
		if(de>0){
			for(int j=h+2;j<h+fh-1;j++)fl+=((lie(j,i)-1)*(fh+h-1-j));
			ansf=(ansf+(fl*de)%mo)%mo;
		}
	}
	ansf+=Vf(f,h+1);
	return ansf;
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>id;
	while(T--){
		cin>>n>>m>>cx>>fx;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>a[i][j];
		LL cans=Vc(cx,1);
		LL fans=Vf(fx,1);
		cout<<cans<<' '<<fans<<'\n';
	}
}