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

ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=1;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}

int const N=1000+3;
ll const Mo=998244353;
ll T,id,n,m,ans1,ans2,x,y,tmp;
int a[N][N],heng[N][N],shu[N][N],numh[N][N];
char cha;

int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read();id=read();
	while (T--){
		n=read();m=read();
		ll c,f;
		c=read();f=read();
		for (int i=1;i<=n;i++){
			for (int j=1;j<=m;j++)
				a[i][j]=getchar()-'0';
			cha=getchar();
		}
		for (int i=1;i<=n;i++){
			heng[i][m+1]=0;
			for (int j=m;j>=1;j--)
				if (a[i][j]==0) heng[i][j]=heng[i][j+1]+1;
				else heng[i][j]=0;
		}
		for (int j=1;j<=m;j++){
			shu[n+1][j]=0;
			for (int i=n;i>=1;i--)
				if (a[i][j]==0) shu[i][j]=shu[i+1][j]+1;
				else shu[i][j]=0;
		}
		for (int j=1;j<=m;j++)
			for (int i=1;i<=n;i++) if (a[i][j]==a[i+1][j] && a[i][j]==0 && heng[i][j]>=2){
				for (int k=i+2;k<=n;k++)
					if (a[k][j]==0){
						if (heng[k][j]>=2){
							x=heng[i][j];
							y=heng[k][j];
							tmp=(y-1)*(x-1)%Mo;
							ans1=(ans1+tmp)%Mo;
							ans2=(ans2+tmp*(shu[k][j]-1)%Mo)%Mo;
						} 
					}
					else{
						break;
					}
			}
		cout<<ans1<<' '<<ans2<<endl;
	}
	return 0;
}