#include<bits/stdc++.h>
using namespace std;
#define N 1010
typedef long long ll;
const int mod=998244353;
inline void inc(int &x,int y){(x+=y)>=mod?x-=mod:233;}
char s[N][N];
int n,m,R[N][N],D[N][N];
void init(){
	memset(R,0,sizeof(R));
	memset(D,0,sizeof(D));
	for(int i=1;i<=n;++i){
		for(int j=m;j>=1;--j){
			R[i][j]=s[i][j]=='0'?R[i][j+1]+1:0;
		}
	}
	for(int j=1;j<=m;++j){
		for(int i=n;i>=1;--i){
			D[i][j]=s[i][j]=='0'?D[i+1][j]+1:0;
		}
	}
}
int calcC(){
	int ans=0;
	for(int j=1;j<=m;++j){
		int tot=0;
		for(int i=n;i>=1;--i){
			if(i+2<=n){
				if(s[i+2][j]=='1')tot=0;
				else inc(tot,(R[i+2][j]-1));
			}
			if(s[i+1][j]=='0'&&s[i][j]=='0'){
				inc(ans,1LL*tot*(R[i][j]-1)%mod);
			}
		}
	}
	return ans;
}
int calcF(){
	int ans=0;
	for(int j=1;j<=m;++j){
		int tot=0;
		for(int i=n;i>=1;--i){
			if(i+2<=n){
				if(s[i+2][j]=='1')tot=0;
				else inc(tot,1LL*(R[i+2][j]-1)*(D[i+2][j]-1)%mod);
			}
			if(s[i+1][j]=='0'&&s[i][j]=='0'){
				inc(ans,1LL*tot*(R[i][j]-1)%mod);
			}
		}
	}
	return ans;
}
void Solve(){
	int C,F;
	cin>>n>>m>>C>>F;
	for(int i=1;i<=n;++i){
		cin>>(s[i]+1);
	}
	init();
	cout<<(C?calcC():0)<<' '<<(F?calcF():0)<<'\n';
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T,Taskid;
	cin>>T>>Taskid;
	while(T--){
		Solve();
	}
	return 0;
}
