#include<bits/stdc++.h>
#define int long long 
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,a,b) for ( int i=(a);i>=(b);i-- )
using namespace std;
const int N=1e3+5;
const int Mo=998244353;
int T,id,n,m,c,f,a[N][N],b[N][N];
inline void add(int &x,int y) { x+=y; if(x>=Mo) x=x-Mo; }
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld%lld",&T,&id);
	for (;T--;) 
	{
		scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
		For(i,1,n) For(j,1,m) scanf("%1lld",&a[i][j]);
		For(i,1,n) Dow(j,m,1) b[i][j]=(!a[i][j])?b[i][j+1]+1:0ll;
		int ansc=0,ansf=0;
		For(j,1,m) 
		{
			int tmp=0ll,ltmp=0,ltmp1=0,tmp1=0,gs=0;
			Dow(i,n,1) if(!a[i][j])
			{
				add(ansf,ltmp1*(b[i][j]-1)%Mo);
				add(ansc,ltmp*(b[i][j]-1)%Mo);
				ltmp=tmp;
				ltmp1=tmp1;
				add(tmp,b[i][j]-1);
				add(tmp1,(b[i][j]-1)*gs%Mo);
				gs++;
			}
			else tmp=ltmp=tmp1=ltmp1=gs=0;
		}
		if(!c) ansc=0;
		if(!f) ansf=0;
		printf("%lld %lld\n",(ansc+Mo)%Mo,(ansf+Mo)%Mo);
		For(i,0,n) For(j,0,m) b[i][j]=0;
	}
	return 0;
}
