#include<bits/stdc++.h>
using namespace std;
#define N 1005
#define ll long long
const int mod=998244353;
int n,m,c,f,T,id;
bool g[N][N];
ll vc,vf;
ll r1[N][N],r2[N][N];
string s;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>id;
	while(T--){
		cin>>n>>m>>c>>f;
		vc=0,vf=0;
		for(int i=1;i<=n;i++){
			cin>>s;
			s=" "+s;
			for(int j=1,len=s.size();j<len;j++){
				if(s[j]=='1') g[i][j]=1;
				else g[i][j]=0;
			}
		}
		if(c==0&&f==0){
			cout<<"0 0"<<endl;
			continue;
		}
		for(int i=1;i<=n;i++){
			for(int j=1,tmp,sum;j<=m;j++){
				if(g[i][j]) continue;
				tmp=j;
				sum=0;
				for(j++;!g[i][j]&&j<=m;j++,sum++);
				for(int x=tmp;x<j;x++) r1[i][x]=sum--;
			}
		}
		for(int j=1;j<=m;j++){
			for(int i=1,sum,tmp;i<=n;i++){
				if(g[i][j]) continue;
				tmp=i;
				sum=0;
				for(i++;!g[i][j]&&i<=n;i++,sum++);
				for(int x=tmp;x<i;x++) r2[x][j]=sum--;
			}
		}
		for(int j=1;j<=m;j++){
			for(int i=1;i<=n;i++){
				if(g[i][j]||g[i+1][j]||g[i+2][j]) continue;
				for(int k=i+2;k<=n;k++){
					if(g[k][j]) break;
					if(c){
						vc+=r1[k][j]*r1[i][j];
						if(vc>mod) vc-=mod;
					}
				 	if(f){
						vf+=r1[k][j]*r1[i][j]*r2[k][j];
						if(vf>mod) vf-=mod;
					}
				}
			}
		}
		cout<<vc<<" "<<vf<<endl;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				r1[i][j]=0,r2[i][j]=0;
			}
		}
	}
	return 0;
}
