#include<bits/stdc++.h>
#define int long long
using namespace std;

int read(){
	int x=0,f=1; char ch=getchar();
	while (!isdigit(ch)){ if (ch=='-') f=-1; ch=getchar(); }
	while (isdigit(ch)){ x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
bool ST;
const int N=2005;
const int Mod=998244353;

int n,m,C,F;
int rg[N][N],dn[N][N],sumC[N][N],sumF[N][N];
char a[N][N];

void Clear(){
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			rg[i][j]=0,dn[i][j]=0,sumC[i][j]=0,sumF[i][j]=0;
}

bool ED;

signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(false);
	int T,id; cin>>T>>id;
	while (T--){
		cin>>n>>m>>C>>F;
		for (int i=1;i<=n;++i) cin>>(a[i]+1);
		for (int i=1;i<=n;++i)
			for (int j=m;j>=1;--j)
				if (a[i][j]=='1') rg[i][j]=0;
				else rg[i][j]=rg[i][j+1]+1;
		for (int j=1;j<=m;++j)
			for (int i=n;i>=1;--i)
				if (a[i][j]=='1') dn[i][j]=0;
				else dn[i][j]=dn[i+1][j]+1;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				if (a[i][j]=='0') --rg[i][j],--dn[i][j];
		
		for (int j=1;j<=m;++j) sumC[n+1][j]=0;
		for (int j=1;j<=m;++j)
			for (int i=n;i>=1;--i)
				if (a[i][j]=='1') sumC[i][j]=0;
				else sumC[i][j]=(sumC[i+1][j]+rg[i][j])%Mod;
		
		for (int j=1;j<=m;++j) sumF[n+1][j]=0;
		for (int j=1;j<=m;++j)
			for (int i=n;i>=1;--i)
				if (a[i][j]=='1') sumF[i][j]=0;
				else sumF[i][j]=(sumF[i+1][j]+rg[i][j]*dn[i][j]%Mod)%Mod;
		//printf("rg :\n"); for (int i=1;i<=n;++i){ for (int j=1;j<=m;++j) printf("%lld ",rg[i][j]); printf("\n"); }
		//printf("dn :\n"); for (int i=1;i<=n;++i){ for (int j=1;j<=m;++j) printf("%lld ",dn[i][j]); printf("\n"); }
		//printf("sumC:\n"); for (int i=1;i<=n;++i){ for (int j=1;j<=m;++j) printf("%lld ",sumC[i][j]); printf("\n"); }
		//printf("sumF:\n"); for (int i=1;i<=n;++i){ for (int j=1;j<=m;++j) printf("%lld ",sumF[i][j]); printf("\n"); }
		int ansC=0;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				if ((a[i][j]=='0') && (a[i+1][j]=='0') && (a[i+2][j]=='0'))
					ansC=(ansC+rg[i][j]*sumC[i+2][j]%Mod)%Mod;
		
		int ansF=0;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				if ((a[i][j]=='0') && (a[i+1][j]=='0') && (a[i+2][j]=='0'))
					ansF=(ansF+rg[i][j]*sumF[i+2][j]%Mod)%Mod;
		printf("%lld %lld\n",C*ansC%Mod,F*ansF%Mod);
		Clear();
	}
	// cerr<<"MemoryUsed:"<<1.0*abs(&ST-&ED)/1024/1024<<endl;
	return 0;
}











