//Can Zhang Tao AK NOIP?
#include<bits/stdc++.h>
using namespace std;
unsigned long long MMOD=998244353,FF,CC;
bool zhiyin;
struct edge
{
	unsigned long long DowN,RighT,LJ,LJD;
	bool CoulD;
}maap[1005][1005];
int readd()
{
	int f=1,x=0;
	char str=getchar();
	while(str<'0'||str>'9')
	{
		if(str=='-')
		 f=-1;
		str=getchar();
	}
	while(str>='0'&&str<='9')
	 x=x*10+str-'0',str=getchar();
	return x*f;
}
void dp(int n,int m)
{
	int i,j,k;
	unsigned long long FFF=0;
	for(i=n;i>=1;i--)
	{
		for(j=m;j>=1;j--)
		{
			if(maap[i][j+1].CoulD==false&&j!=m)
			 maap[i][j].RighT=(maap[i][j+1].RighT+1)%MMOD;
			if(maap[i+1][j].CoulD==false&&i!=n)
			 maap[i][j].DowN=(maap[i+1][j].DowN+1)%MMOD,maap[i][j].LJD=(maap[i+1][j].LJD+((maap[i+2][j].RighT*maap[i+2][j].DowN)%MMOD))%MMOD;
			if(maap[i+1][j].CoulD==false&&maap[i+2][j].CoulD==false)
			 maap[i][j].LJ=(maap[i+1][j].LJ+maap[i+2][j].RighT)%MMOD;
		}
	}
	for(i=1;i<=n-2;i++)
	 for(j=1;j<=m-1;j++)
	 {
	 	if(maap[i][j].CoulD==false)
	 	{
	 		CC=(CC+((maap[i][j].RighT*maap[i][j].LJ)%MMOD))%MMOD;
	 		if(i!=n-2)
	 		 FF=(FF+(maap[i][j].RighT*maap[i][j].LJD)%MMOD)%MMOD;
	 	}
	 }
	zhiyin=true;
//	cout<<maap[1][1].LJ<<endl;
//	cout<<maap[2][1].LJ<<endl;
//	cout<<maap[3][1].RighT<<endl;
//	cout<<maap[4][1].RighT<<endl;
//  114514
	return ;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int n,m,T,ID,i,j,c,f;
	char str;
	T=readd(),ID=readd();
	while(T--)
	{
		n=readd(),m=readd(),c=readd(),f=readd();
		zhiyin=false,FF=CC=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			 str=getchar(),maap[i][j].CoulD=(str=='0'?false:true),maap[i][j].DowN=maap[i][j].RighT=maap[i][j].LJ=maap[i][j].LJD=0;
			str=getchar();
		}
		if(c==0)
		 cout<<"0 ";
		else
		 dp(n,m),cout<<CC%MMOD<<' ';
		if(f==0)
		 cout<<"0"<<endl;
		else
		{
			if(zhiyin==false)
			 dp(n,m);
			cout<<FF%MMOD<<endl;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}