#include<iostream>
#include<cstdio>
#define maxn 1005
#define mod 998244353
#define ll long long
using namespace std;
int T,id,n,m,c,f,h[maxn][maxn],h2[maxn][maxn],p[maxn][maxn]; bool a[maxn][maxn];
ll ans=0,ans2=0,pre[maxn][maxn],pre2[maxn][maxn];
void set(){
	for(int i=0;i<=n+4;i++) for(int j=0;j<=m+4;j++)
		{h[i][j]=h2[i][j]=p[i][j]=0; pre[i][j]=pre2[i][j]=a[i][j]=0LL;} ans=0LL; ans2=0LL;
}
void calc(){
	for(int j=1;j<=m;j++) for(int i=1;i<=n-2;i++) if(!a[i][j]&&p[i][j]>i+1){
		ans=(ans+1LL*h[i][j]*(pre[p[i][j]][j]-pre[i+1][j])%mod)%mod;
		ans2=(ans2+1LL*h[i][j]*(pre2[p[i][j]][j]-pre2[i+1][j])%mod)%mod;
	}
}
int main(){
	freopen("plant.in","r",stdin); freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id); while(T--){
		scanf("%d%d%d%d",&n,&m,&c,&f); set();
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%1d",&a[i][j]);
		for(int i=1;i<=n;i++)
			{int res=0; for(int j=m;j;j--) if(!a[i][j]) h[i][j]=res++; else res=0;}
		for(int j=1;j<=m;j++) for(int i=1;i<=n+1;i++) pre[i][j]=pre[i-1][j]+1LL*h[i][j];
		for(int j=1;j<=m;j++)
			{int pos=n+1; for(int i=n;i;i--) if(!a[i][j]) p[i][j]=pos; else p[i][j]=pos=i;}
		for(int i=1;i<=n;i++) for(int j=m;j;j--) h2[i][j]=h[i][j]*(p[i][j]-i-1);
		for(int j=1;j<=m;j++) for(int i=1;i<=n+1;i++) pre2[i][j]=pre2[i-1][j]+1LL*h2[i][j];
		calc(); printf("%lld %lld\n",c*ans%mod,f*ans2%mod);
	}
	return 0;
}
/*
By qzhwlzy
T1 plant
------code------
point 1~16 -> 100pts
starts at  8:37
ends   at  9:39
----------------
*/

