#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1008,mod=998244353;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}
	return x*f;
}
int n,m,i,j,k,t,c,f;
int a[N][N],len[N][N],up[N][N],down[N][N],id;
int ans1,ans2;
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	t=read();id=read();
	while(t--){
		n=read(),m=read(),c=read(),f=read();
		ans1=ans2=0;
		memset(len,0,sizeof(len));
		memset(up,0,sizeof(up));
		memset(down,0,sizeof(down));
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				char x;cin>>x;
				a[i][j]=x-'0';
			}
		}
		for(i=1;i<=n;i++){
			for(j=m;j>=1;j--){
				if(!a[i][j]){
					len[i][j]=len[i][j+1]+1;
				}
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
			  if(!a[i][j]){
			  	up[i][j]=up[i-1][j]+(len[i][j]-1);
			  }	
			}
		}
		for(i=n;i>=1;i--){
			for(j=1;j<=m;j++){
				if(!a[i][j]){
					down[i][j]=down[i+1][j]+1;
				}
			}
		}
        for(i=1;i<=n;i++){
        	for(j=1;j<=m;j++){
        		if(!a[i][j]&&(!a[i-1][j])){
        			ans1=(ans1+up[i-2][j]*(len[i][j]-1))%mod;
        			ans2=(ans2+up[i-2][j]*(len[i][j]-1)*down[i+1][j])%mod;
				}
			}
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}