#include<bits/stdc++.h>
using namespace std;
const int TT=998244353;
int t,n,m,C,F;
int mp[1005][1005],fx[1005][1005],fy[1005][1005],f[1005][1005];
long long L,R;
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	t=read();read();
	while(t--){
		n=read();m=read();C=read();F=read();
		for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
		mp[i][j]=1-getchar()+'0';
		if(i!=n)getchar();
		}
		for(int i=1;i<=n;i++)
		for(int j=m;j>=1;j--)if(mp[i][j])fx[i][j]=fx[i][j+1]+1;
		for(int i=n;i>=1;i--)
		for(int j=1;j<=m;j++)if(mp[i][j])fy[i][j]=fy[i+1][j]+1;
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)if(mp[i][j])f[i][j]=f[i-1][j]+fx[i][j]-1;
		
		for(int i=3;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(mp[i][j]&&mp[i-1][j]&&mp[i-2][j])L=(L+(long long)(fx[i][j+1]*(long long)(f[i-1][j]-fx[i-1][j]+1)))%TT,R=(R+(long long)(fx[i][j+1]*(long long)(f[i-1][j]-fx[i-1][j]+1)*fy[i+1][j]))%TT;
		}
		printf("%lld %lld\n",L*C%TT,R*F%TT);
	}
	return 0;                           
}