#include <bits/stdc++.h>
using namespace std;

const int mo=998244353;
int T,id,n,m,c,f;
char tu[1005][1005];

void check1()
{
	int ans=0,shang,xia;
	
	for(int i=1;i<=m;i++)//mei ju y0
	{
		for(int j=1;j<=n-2;j++)//mei ju x1
		{
			if(tu[j][i]=='0' and tu[j+1][i]=='0')
			{
				//cout << j << " " << i << endl;
				shang=0;
				for(int k=i+1;k<=m;k++)//mei ju y1
				{
					if(tu[j][k]=='1') break;
					else shang++;
				}
				if(shang)
				{
					for(int l=j+2;l<=n;l++)//mei ju x2
					{
						if(tu[l][i]=='0')
						{
							xia=0;
							for(int o=i+1;o<=m;o++)//mei ju y2
							{
								if(tu[l][o]=='1') break;
								else xia++;
							}
							ans+=1ll*shang*xia%mo;
						}
						else break;
					}
				}
			}
		}
	}
	
	printf("%d 0\n",ans%mo);
	
	return;
}

void check2()
{
	int ansc=0,ansf=0,shang,xia,wei;
	
	for(int i=1;i<=m;i++)//mei ju y0
	{
		for(int j=1;j<=n-2;j++)//mei ju x1
		{
			if(tu[j][i]=='0' and tu[j+1][i]=='0')
			{
				//cout << j << " " << i << endl;
				shang=0;
				for(int k=i+1;k<=m;k++)//mei ju y1
				{
					if(tu[j][k]=='1') break;
					else shang++;
				}
				if(shang)
				{
					for(int l=j+2;l<=n;l++)//mei ju x2
					{
						if(tu[l][i]=='0')
						{
							xia=0;
							for(int o=i+1;o<=m;o++)//mei ju y2
							{
								if(tu[l][o]=='1') break;
								else xia++;
							}
							if(xia)
							{
								wei=0;
								ansc=(ansc+1ll*shang*xia%mo)%mo;
								for(int p=l+1;p<=n;p++)
								{
									if(tu[p][i]=='1') break;
									else wei++;
								}
								ansf=(ansf+1ll*shang*xia*wei%mo)%mo;
							}
						}
						else break;
					}
				}
			}
		}
	}
	printf("%d %d\n",ansc,ansf);
	
	return;
}

int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	
	scanf("%d%d",&T,&id);
	
	while(T--)
	{
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=1;i<=n;i++)
		{
			scanf("\n");
			for(int j=1;j<=m;j++)
				scanf("%c",&tu[i][j]);
		}
		
		if(c==0 and f==0) printf("0 0\n");
		else if(f==0) check1();
		else check2();
	}
	
	
	return 0;
	
}
