#include<bits/stdc++.h>
using namespace std;
#define N 1005
int read(){
	int w=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')f=(c=='-'?-f:f),c=getchar();
	while(c>='0'&&c<='9')w=w*10+c-'0',c=getchar();
	return w*f;
}
int readc(){
	char c=getchar();
	while(c!='0'&&c!='1')c=getchar();
	return c=='1'?1:0;
}
const int mod=998244353;
int T,Tid,n,m,ans1,ans2,C,F,a[N][N],r[N][N],d[N][N];
void inc(int&x,int y){
	x+=y,x=x>=mod?x-mod:x;
}
void solve(){
	n=read(),m=read(),C=read(),F=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=readc();
	for(int i=1;i<=n;i++){
		int now=0;
		for(int j=m;j>0;j--)
			if(a[i][j])r[i][j]=0,now=0;
			else r[i][j]=now,now++;
	}
	for(int i=1;i<=m;i++){
		int now=0;
		for(int j=n;j>0;j--)
			if(a[j][i])d[j][i]=0,now=0;
			else d[j][i]=now,now++;
	}
	for(int i=1;i<=m;i++){
		int now=0;
		for(int j=1;j<n-1;j++){
			if(a[j][i])now=0;
			else inc(now,r[j][i]);
			if(!a[j+1][i])inc(ans1,1ll*now*r[j+2][i]%mod),inc(ans2,1ll*now*r[j+2][i]%mod*d[j+2][i]%mod);
		}
	}
	ans1=1ll*ans1*C%mod,ans2=1ll*ans2*F%mod;
	printf("%d %d\n",ans1,ans2);
}
void clear(){
	ans1=0,ans2=0;
}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read(),Tid=read();
	while(T--)
		solve(),clear();
	return 0;
}