#include<bits/stdc++.h>
using namespace std;
long long i,j,n,m,k,l,c,ans,f,MOD=998244353;
int a[1005][1005],b[1005][1005][3];
inline int read()
{
	bool f=0;int x=0;char c=getchar();
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if (f) x=-x;return x;
}
inline void getans1(int x,int y)
{
	int k=0;
	for (register int i=x+2;i<=x+b[x][y][2]-1;i++)
		k=k+max(0,b[i][y][1]-1);
	k=(k*(b[x][y][1]-1))%MOD;
	ans=(ans+k)%MOD;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t=read(),id=read();
	while(t--)
	{
		n=read();m=read();c=read();f=read();
		for (register int i=1;i<=n;i++)
		  for (register int j=1;j<=m+1;j++) a[i][j]=int(getchar())-48;
		if (c==0&&f==0) {cout<<"0 0"<<endl;continue;}
		for (register int i=1;i<=n;i++)
		{
			int x=0;
		  	for (register int j=m;j>=1;j--)
		  	{
		  		if (a[i][j]==1) x=0;
		  		  else x+=1;
		  		b[i][j][1]=x;
		  	}
		}
		for (register int i=1;i<=m;i++)
		{
			int x=0;
		  	for (register int j=n;j>=1;j--)
		  	{
		  		if (a[j][i]==1) x=0;
		  		  else x+=1;
		  		b[j][i][2]=x;
		  	}
		}
		for (register int i=1;i<=n;i++)
		  for (register int j=1;j<=m;j++)
		    if ((b[i][j][1]>=2)&&(b[i][j][2]>=3)) getans1(i,j);
		cout<<ans<<' ';
		ans=0;
		if (f==0) {cout<<0<<endl;continue;}
		for (register int i=1;i<=m;i++)
		  for (register int j=1;j<=n;j++)
		    if ((b[j][i][1]>=2)&&(b[j][i][2]>=4))
		    {
		    	int q=j+2;k=0;
		    	while((q<=n)&&(a[q][i]==0))
		    	{
		    		if ((b[q][i][1]>=2)&&(b[q][i][2]>=2))
					  k=k+max(0,b[q][i][1]-1)*(b[q][i][2]-1);
		    		q+=1;
				}
				k=(k*(b[j][i][1]-1))%MOD;
				ans=(ans+k)%MOD;j=q;
			}
		cout<<ans<<endl;
	}
	
	return 0;
}