#include<bits/stdc++.h>
using namespace std;
const int Mod=998244353;
int vis[1010][1010]={0},val[1010][1010]={0},vis1[1010][1010]={0},max1[1010][1010],top[1010][1010];
long long sum1[1010][1010]={0};
long long ans=0,ans2=0;
void init(int n,int m){
	ans=0,ans2=0;
	for(int i=1;i<=m;i++) vis[n+1][i]=0,val[n+1][i]=0;
	for(int i=1;i<=n;i++) val[i][m+1]=0,vis[i][m+1]=0;
	for(int i=1;i<=n;++i){
		for(int j=m;j>=1;--j){
			vis1[i][j]=0;
			sum1[i][j]=0;
			max1[i][j]=0;
			top[i][j]=0;
			if(vis[i][j]==1){
				val[i][j]=0;
				continue;
			}
			val[i][j]=val[i][j+1]+1;
		}
	}
}
void solvec(int x,int y){
	for(int i=1;i<=y;i++){
		int cnt=1;
		top[i][cnt]=0;
		for(int j=1;j<=x;j++){
			if(vis[j][i]==1){
				sum1[j][i]=0;
				if(vis[j-1][i]==0){
					max1[i][cnt]=j-1;
					cnt++;
				}
				top[i][cnt]=j;
				vis1[j][i]=cnt;
				continue;
			}
			max1[i][cnt]=x;
			vis1[j][i]=cnt;
			sum1[j][i]=sum1[j-1][i]+(val[j][i]-1);
		}
	}
	for(int i=1;i<=x;i++)
	for(int j=1;j<=y;j++){
		int cnt=vis1[i][j];
		int maxnum=max1[j][cnt];
		if(val[i][j]>=1&&maxnum>=i+2){
			int num=sum1[maxnum][j]-sum1[i][j]-val[i+1][j]+1;
			ans+=(val[i][j]-1)*num;
			ans=ans%Mod;
		}
	}
	for(int i=x;i>=1;i--)
	for(int j=y;j>=1;j--){
		int cnt=vis1[i][j];
		int minnum=top[j][cnt];
		int maxnum=max1[j][cnt];
		if(val[i][j]>=2&&minnum<=i-2){
			int num=sum1[i-2][j];
			ans2+=(maxnum-i)*num*(val[i][j]-1);
			ans2=ans2%Mod;
		}
	}
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%d%d",&T,&id);
	while(T--){
		int n,m,c,f;
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=1;i<=n;i++){
			string s;
			cin>>s;
			for(int j=1;j<=m;j++){
				if(s[j-1]=='0') vis[i][j]=0;
				else vis[i][j]=1;
				val[i][j]=0;
			}
		}
		init(n,m);
		solvec(n,m);
		cout<<ans<<" "<<ans2<<endl;
	}
	fclose(stdin);
	fclose(stdout);
}
