#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,m,C,F,id;
const int MOD=998244353;
int a[1005][1005],g[1005][1005];
int sum[1005][1005],f[1005][1005],gf[1005][1005],sumgf[1005][1005];
char s[2005];
int ans,tk;
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld%lld",&T,&id);
	while(T--){
		ans=0,tk=0;
		memset(a,0,sizeof(a));
		memset(g,0,sizeof(g));
		memset(f,0,sizeof(f));
		memset(gf,0,sizeof(gf));
		memset(sumgf,0,sizeof(sumgf));
		memset(sum,0,sizeof(sum));
		scanf("%lld%lld%lld%lld",&n,&m,&C,&F);
		for(int i=1;i<=n;i++){
			scanf("%s",s+1);
			for(int j=1;j<=m;j++)
				a[i][j]=s[j]-'0';
		}
		for(int i=1;i<=n;i++)
			a[i][m+1]=1;
		for(int j=1;j<=m;j++)
			a[n+1][j]=1;
		for(int i=1;i<=n;i++){
			int now=1;
			for(int j=1;j<=m;j++){
				if(a[i][j])continue;
				if(now<=j)now=j+1;
				while(a[i][now]==0)now++;
				g[i][j]=now-j-1;
			}
		}
		for(int j=1;j<=m;j++)
			for(int i=1;i<=n;i++)
				sum[i][j]=(sum[i-1][j]+g[i][j])%MOD;
		for(int j=1;j<=m;j++){
			int now=1;
			for(int i=1;i<=n;i++){
				if(a[i][j])continue;
				if(now<=i)now=i+1;
				while(a[now][j]==0)now++;
				f[i][j]=now-i-1;
			}
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				gf[i][j]=g[i][j]*f[i][j]%MOD;
		for(int j=1;j<=m;j++)
			for(int i=1;i<=n;i++)
				sumgf[i][j]=(sumgf[i-1][j]+gf[i][j])%MOD;
		for(int j=1;j<=m;j++){
			for(int i=1;i<=n;i++){
				if(f[i][j]==0)continue;
				ans+=g[i][j]*(sum[i+f[i][j]][j]-sum[i+1][j]+MOD);
				tk+=g[i][j]*(sumgf[i+f[i][j]][j]-sumgf[i+1][j]+MOD);
				ans%=MOD;
				tk%=MOD;
			}
		}
		printf("%lld %lld\n",ans*C%MOD,tk*F%MOD);
	}
}