//That was hope.
//Though we need mod 998244353,we still have bright future.
//My FuZaDu fixed.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace IO
{
	char buf[1<<20],*iS,*iT;
	//#define gh() (iS==iT?iT=(iS=buf)+fread(buf,1,1<<20,stdin),(iS==iT?EOF:*iS++):*iS++)
	#define gh() getchar()
	template<typename T>
	inline void read(T &x)
	{
		x=0;
		char c=gh();
		bool sgn=0;
		while(!isdigit(c))
			sgn|=c=='-',c=gh();
		while(isdigit(c))
			x=x*10+(c^48),c=gh();
		x=sgn?-x:x;
	}
}
using namespace IO;
int t,id,n,m,/*c*/c,f;
const int maxn=1e3+5;
const int mo=998244353;
ll ansc,ansf;
char mp[maxn][maxn];
int bk[maxn][maxn],tail[maxn][maxn];
ll qz[maxn][maxn],qzt[maxn][maxn];
//vector<int>row[maxn],col[maxn];
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	read(t),read(id);
	for(int kkk=0;kkk<t;++kkk)
	{
		read(n),read(m),read(c),read(f);
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=m;++j)
			{
				char c=getchar();
				while(c!='0'&&c!='1')
					c=getchar();
				mp[i][j]=c;
			}
		}
		if(c==1)
		{
//			for(int i=1;i<=n+1;++i)
//				for(int j=1;j<=m+1;++j)
//					mp[i][j]='2';
			ansc=ansf=0;
			for(int i=1;i<=n;++i)
				bk[i][m+1]=-1;
			for(int i=1;i<=m;++i)
				tail[n+1][i]=-1;
			for(int i=1;i<=m;++i)
				qz[n+1][i]=qzt[n+1][i]=0;
			for(int i=n;i;--i)
			{
				for(int j=m;j;--j)
				{
					if(mp[i][j]=='0')
						bk[i][j]=bk[i][j+1]+1;
					else
						bk[i][j]=-1;
				}
			}
			for(int j=m;j;--j)
			{
				for(int i=n;i;--i)
				{
					if(mp[i][j]=='0')
						tail[i][j]=tail[i+1][j]+1;
					else
						tail[i][j]=-1;
				}
			}
			for(int j=m;j;--j)
			{
				for(int i=n;i;--i)
				{
					if(mp[i][j]=='0')
						qz[i][j]=qz[i+1][j]+bk[i][j],
						qzt[i][j]=qzt[i+1][j]+bk[i][j]*tail[i][j];
					else
						qz[i][j]=qzt[i][j]=0;
				}
			}
//			for(int i=1;i<=n;++i)
//			{
//				for(int j=1;j<=m;++j)
//					printf("<%d> ",tail[i][j]);
//				putchar('\n');
//			}
			for(int x1=1;x1<=m;++x1)
			{
				for(int y0=1;y0<n;++y0)
				{
					if(mp[y0][x1]!='0')
					{
//						puts("<case 1>");
//						printf("<x1:%d y1:%d>\n",x1,y0);
						continue;
					}
					if(mp[y0+1][x1]!='0')
					{
//						puts("<case 2>");
//						printf("<x1:%d y1:%d>\n",x1,y0);
						continue;
					}
//					for(int y2=y0+2;y2<=n;++y2)
//					{
//						if(mp[y2][x1]!='0')
//							break;
//						int tmp=bk[y0][x1]*bk[y2][x1];
//						//printf("<tmp:%d>\n",tmp);
//						//printf("<x1:%d y1:%d y2:%d>\n",x1,y0,y2);
//						ansc=(ansc+tmp)%mo;
//						if(f==1)
//							ansf=(ansf+(ll)tmp*tail[y2][x1])%mo;
//					}
					ansc=(ansc+bk[y0][x1]*qz[y0+2][x1])%mo;
					if(f==1)
						ansf=(ansf+bk[y0][x1]*qzt[y0+2][x1])%mo;
				}
			}
			printf("%lld %lld\n",ansc,ansf);
		}
		else
			puts("0");
	}
	
	return 0;
}

