#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=1;i<=n;i++)
const int mod= 998244353;
using namespace std;
int Read(){
	char ch=getchar();
	int x=0;
	if(ch==EOF)return 0;
	while(ch<'0'||ch>'9') ch=getchar();
	if(ch==EOF)return 0;
	while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}
bool mp[1005][1005];
struct count{
	int u,r;//already contain itself
	//**from** up/right
}ans[1005][1005];
int dp[1005][1005];
int sc[1005][1005];//conut from top;how many Cs are up there
int sum[1005][1005];//conut from top;how much can go forward
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T=Read(),id=Read();
	while(T--){
		memset(dp,0,sizeof(dp));
		memset(ans,0,sizeof(ans));
		memset(sum,0,sizeof(sum));
		memset(sc,0,sizeof(sc));
		memset(mp,0,sizeof(mp));
		int n=Read(),m=Read();
		short c=Read(),f=Read();
		char ch;
		rep(i,n)rep(j,m){
			ch=getchar();
			while(ch!='0'&&ch!='1')ch=getchar();
			mp[i][j]=ch^48;		
			if(mp[i][j]) ans[i][j].u=0;
			else ans[i][j].u=ans[i-1][j].u+1;	
		}
		rep(i,n)for(int j=m;j>=1;j--){
			if(mp[i][j]) ans[i][j].r=0;
			else ans[i][j].r=ans[i][j+1].r+1;	
		}
		int vc=0,vf=0;
		rep(i,n)rep(j,m){
			sum[i][j]=(sum[i-1][j]+ans[i][j].r-1)%mod;
			if(!mp[i][j]&&ans[i][j].u>2)dp[i][j]=((ans[i][j].r-1)*((sum[i-2][j]-sum[i-ans[i][j].u][j]+mod)%mod)%mod),vc+=dp[i][j],vc%=mod;
			if(!mp[i][j])sc[i][j]=(sc[i-1][j]+dp[i][j])%mod,vf+=sc[i-1][j],vf%=mod;
			else sc[i][j]=0;
//			printf("%lld",dp[i][j]);
//		}printf("\n");
		}
		printf("%lld %lld\n",vc*c%mod,vf*f%mod);
	}
	return 0;
}
/*
dp[i][j][0]
don't forget to memset!
*/
