#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;
const int HgS=998244353;
int T,id,n,m,c,f,a,b,rt[N][N],ca[N][N],cb[N][N],cc[N][N];
char s[N][N];
void add(int& x,int y){
	x+=y;
	if(x>=HgS)
		x-=HgS;
}
void solve(){
	memset(rt,0,sizeof(rt));
	memset(ca,0,sizeof(ca));
	memset(cb,0,sizeof(cb));
	memset(cc,0,sizeof(cc));
	scanf("%d%d%d%d",&n,&m,&c,&f);
	for(int i=1;i<=n;++i)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i){
		rt[i][m+1]=m+1;
		for(int j=m;j;--j){
			if(s[i][j]=='1')
				rt[i][j]=j;
			else
				rt[i][j]=rt[i][j+1];
		}
	}
	for(int i=2;i<=n;++i)
	for(int j=1;j<=m;++j){
		if(s[i][j]=='1')
			continue;
		ca[i][j]=ca[i-1][j];
		if(rt[i-1][j]>j)
			add(ca[i][j],rt[i-1][j]-j-1);
	}
	for(int i=3;i<=n;++i)
	for(int j=1;j<=m;++j){
		if(s[i][j]=='1')
			continue;
		cb[i][j]=1ll*ca[i-1][j]*(rt[i][j]-j-1)%HgS;
	}
	for(int i=4;i<=n;++i)
	for(int j=1;j<=m;++j){
		if(s[i][j]=='1')
			continue;
		cc[i][j]=cc[i-1][j];
		add(cc[i][j],cb[i-1][j]);
	}
	a=b=0;
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j){
		add(a,cb[i][j]);
		add(b,cc[i][j]);
	}
	printf("%d %d\n",c*a,f*b);
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while(T--)
		solve();
	return 0;
}