#include <bits/stdc++.h>
#define ll long long
const int MAXN=1010;
const ll MOD=998244353;
int T,id;
bool g[MAXN][MAXN];
int frt[MAXN][MAXN];
int n,m,is_c,is_f;
ll ansc=0,ansf=0;
void cul_frt()
{
	for(int x1=1;x1<=n;x1++)
	{
		int now=0;
		for(int x2=m;x2>=1;x2--)
		{
			if(g[x1][x2]==0) frt[x1][x2]=now;
			if(g[x1][x2]==1) now=0;
			else now++;
		}
	}
	return ;
}
void preadd()
{
	for(int j=1;j<=m;j++)
		for(int i=2;i<=n;i++)
			frt[i][j]+=frt[i-1][j];
	return ;
}
int getval(int cl,int l,int r)
{
	return frt[r][cl]-frt[l-1][cl];
}
void culc()
{
	for(int j=1;j<=m;j++)
	{
		int upb=-1;
		for(int i=1;i<=n;i++)
		{
			if(g[i][j]==0 && upb==-1) upb=i;
			if(upb!=-1)
			{
				if(g[i][j]==0 && i-upb>=2)
				{
					ansc=(ansc+(1ll)*getval(j,i,i)*getval(j,upb,i-2))%MOD;
				}
				if(g[i][j]==1) upb=-1;
			}
		}
	}
	return ;
}
void culf()
{
	for(int j=1;j<=m;j++)
	{
		int upb=-1,tmp=-1;
		for(int i=1;i<=n;i++)
		{
			if(g[i][j]==0 && upb==-1)
			{
				upb=i;
				tmp=upb;
				while(g[tmp][j]==0) tmp++;
			}
			if(upb!=-1)
			{
				if(g[i][j]==0 && i-upb>=2)
				{
					ansf=(ansf+(((1ll)*getval(j,i,i)*getval(j,upb,i-2))%MOD)*(tmp-i-1))%MOD;
//					printf("%d %d %d\n",getval(j,i,i),getval(j,upb,i-2),(tmp-i-1));
				}
				if(g[i][j]==1) upb=-1,tmp=-1;
			}
		}
	}
	return ;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d %d",&T,&id);
	while(T--)
	{
		memset(g,1,sizeof(g));
		memset(frt,0,sizeof(frt));
		ansc=0,ansf=0;
		scanf("%d %d %d %d",&n,&m,&is_c,&is_f);
		for(int x1=1;x1<=n;x1++)
			for(int x2=1;x2<=m;x2++)
				scanf("%1d",&g[x1][x2]);
		cul_frt();
		preadd();
		if(is_c) culc();
		if(is_f) culf();
		printf("%lld %lld\n",ansc,ansf);
	}
	return 0;
}
