#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define wt(x) write(x),puts("")
inline int read(){
	int x=0,k=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') k=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*k;
}
void write(int x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9){
		write(x/10);
	}
	putchar(x%10+'0');
	return ;
}
const int N=2001,mod=998244353;
int n,m,tot,cnt,ans;
int a[N][N],sum[N][N],sum1[N][N];
char s[N][N];
int solvec(){
	int num=0;
	fo(j,1,m){
		int o=0;
		fo(i,1,n){
			if(s[i][j]=='1'){
				o=0;
			}
			else{
				num=(num+sum[i][j]*o%mod)%mod;
				num=(num-sum[i][j]*sum[i-1][j]%mod+mod)%mod;
				o=(o+sum[i][j])%mod;
			}
		}
	}
	return num;
}
int solvef(){
	int num=0;
	fo(j,1,m){
		int o=0;
		fo(i,1,n){
			if(s[i][j]=='1'){
				o=0;
			}
			else{
				num=(num+sum[i][j]*o%mod*sum1[i][j]%mod)%mod;
				num=(num-sum[i][j]*sum[i-1][j]%mod*sum1[i][j%mod]+mod)%mod;
				o=(o+sum[i][j])%mod;
			}
		}
	}
	return num;
}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int tt=read();
	int nm=read();
	while(tt--){
		n=read();m=read();
		int c=read(),f=read();
		fo(i,1,n) scanf("%s",(s[i]+1));
		fo(i,0,n){
			fo(j,0,m) sum[i][j]=0,sum1[i][j]=0;
		}
		fo(i,1,n){
			int p=0;
			fr(j,m,1){
				if(s[i][j]=='0')sum[i][j]=p;
				if(s[i][j]=='1') p=0;
				else p++;
			}
		}
		fo(j,1,m){
			int p=0;
			fr(i,n,1){
				if(s[i][j]=='0') sum1[i][j]=p;
				if(s[i][j]=='1') p=0;
				else p++;
			}
		}
		printf("%lld %lld\n",solvec()*c,solvef()*f);
	}
}
