#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll t,id,n,m,c,f;
ll qline[1010][1010],qrowc[1010][1010],qrowf[1010][1010],qrow[1010][1010];
ll ansc,ansf;
ll nl[1010][1010];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld %lld",&t,&id);
	while(t--){
		memset(qline,0,sizeof(qline));
		memset(qrowc,0,sizeof(qrowc));
		memset(qrowf,0,sizeof(qrowf));
		memset(qrow,0,sizeof(qrow));
		memset(nl,0,sizeof(nl));
		ansc=ansf=0;
		scanf("%lld %lld %lld %lld",&n,&m,&c,&f);
		for(int i=1;i<=n;i++) qline[i][m+1]=-1;
		for(int i=1;i<=n;i++){
			char c[1010];
			cin>>c+1;
			for(int j=1;j<=m;j++){
				nl[i][j]=c[j]-'0';
			}
			for(int j=m;j>=1;j--){
				if(nl[i][j]==1) qline[i][j]=-1;
				else qline[i][j]=qline[i][j+1]+1;
			}
		}
		for(int j=1;j<=m;j++){
			for(int i=n;i>=1;i--){
				if(nl[i][j]==0) qrow[i][j]=qrow[i+1][j]+1;
			}
		}
		for(int j=1;j<=m;j++){
			for(int i=n-2;i>=1;i--){
				if(nl[i][j]==0 && nl[i+1][j]==0 && nl[i+2][j]==0) qrowc[i][j]=(qrowc[i+1][j]+qline[i+2][j])%mod;
				else qrowc[i][j]=0;
			}
			for(int i=n-3;i>=1;i--){
				if(nl[i][j]==0 && nl[i+1][j]==0 && nl[i+2][j]==0 && nl[i+3][j]==0) qrowf[i][j]=(qrowf[i+1][j]+qline[i+2][j]*(qrow[i+2][j]-1))%mod;
				else qrowf[i][j]=0;
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(nl[i][j]==0) ansc=(ansc+qrowc[i][j]*qline[i][j])%mod,ansf=(ansf+qrowf[i][j]*qline[i][j])%mod;
			}
		}
		cout<<(ansc*c)<<" "<<(ansf*f)<<endl;
	}
	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000

*/