#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define pc putchar
#define ll long long
#define int ll
int read(){
	int ret=0;bool f=1;char c=gc();
	while(!isdigit(c))(c=='-'?f=!f:0),c=gc();
	while(isdigit(c))ret=(ret<<3)+(ret<<1)+(c^48),c=gc();
	return f?ret:-ret;
}
const int mod=998244353;
const int maxn=1e3+5;
int T,n,m,c,f,a[maxn][maxn];
int R[maxn][maxn],D[maxn][maxn];
int vc,vf;
int get(){char c=gc();while(c!='0'&&c!='1')c=gc();return c^48;}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant0.out","w",stdout);
	T=read();read();
	while(T--){
		n=read(),m=read(),c=read(),f=read();memset(R,0,sizeof R),memset(D,0,sizeof D);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)a[i][j]=get();
		if( !c && !f ){printf("0 0\n");break;}
		for(int i=1;i<=n;i++)
		for(int j=m;j;j--)if(a[i][j])R[i][j]=0;else R[i][j]=R[i][j+1]+1;
		for(int j=1;j<=m;j++)
		for(int i=n;i;i--)if(a[i][j])D[i][j]=0;else D[i][j]=D[i+1][j]+1;
		for(int x1=1;x1<=n;x1++)
		for(int y0=1;y0<=m;y0++)if(!a[x1][y0]&&!a[x1+1][y0])
		for(int x2=x1+2;x2<=n;x2++)if(!a[x2][y0]){
			vc=(vc+(R[x1][y0]-1)*(R[x2][y0]-1))%mod;
			vf=(vf+(R[x1][y0]-1)*(R[x2][y0]-1)*(D[x2][y0]-1))%mod;
		}else break;
		printf("%lld %lld\n",(c*vc)%mod,(f*vf)%mod);
	}
	return 0;
}