#include<bits/stdc++.h>
using namespace std;
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define IO ios::sync_with_stdio(0)
#define ll long long
inline void rd(int &x) {
	x=0;
	bool f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')f=1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	if(f)x=-x;
}
const int N=1005,M=998244353;
int n,m,c,f,i,j,tot,k,T,id;
int s[N][N],z[N][N];
ll ans,a[N];
bool b[N][N];
char ch;

inline void pre(){
	for(i=1;i<=n;++i)s[i][m+1]=0;
	for(i=1;i<=m;++i)z[n+1][i]=0;
	for(i=n;i;--i){
		for(j=m;j;--j){
			if(b[i][j])s[i][j]=z[i][j]=0;
			else s[i][j]=s[i][j+1]+1,z[i][j]=z[i+1][j]+1;
		}
	}
}

inline void fc() {
	ans=0;
	for(j=1;j<m;++j){
		for(i=1;i<n-1;++i){
			if(b[i][j]||z[i][j]<3||(i>1&&!b[i-1][j]))continue;
			tot=0;
			for(k=i;k<i+z[i][j];++k){
				if(k-1>i)tot+=s[i-2][j];
				ans=(ans+1ll*tot*s[i][j]%M)%M;
			}
		}
	}
	printf("%lld ",ans);
	return;
}
inline void ff() {

	printf("%lld\n",ans);
	return;
}

int main() {
	//fr("plant");
	rd(T),rd(id);
	while(T--) {
		rd(n),rd(m),rd(c),rd(f);
		for(i=1; i<=n; ++i) {
			for(j=1; j<=m; ++j) {
				scanf("%c",&ch);
				b[i][j]=(ch=='1');
			}
		}
		if(c==0&&f==0)printf("0 0");
		else {
			pre();
			fc(),ff();
		}
	}
	return 0;
}