#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=1005;
long long c[N][N],f[N][N];
long long ansc=0,ansf=0;
long long T,id,n,m,C,F,a[N][N];
inline void dfsc(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(c[i][j]<=1){
				continue;
			}
			int c1=c[i][j];
			for(int k=i+2;k<=i+f[i][j]-1;k++){
				int c2=c[k][j];
				ansc+=(((c1-1)%mod)*((c2-1)%mod)*C)%mod;
				ansf+=(((c1-1)%mod)*((c2-1)%mod)*((i+f[i][j]-1-k)%mod)*F)%mod;
				ansc%=mod;
				ansf%=mod;
			}
		}
	}
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld%lld",&T,&id);
	while(T--){
		memset(f,0,sizeof(f));
		memset(c,0,sizeof(c));
		memset(a,0,sizeof(a));
		ansc=ansf=0;
		scanf("%lld%lld%lld%lld",&n,&m,&C,&F);
		C%=mod;
		F%=mod;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				char s;
				cin>>s;
				a[i][j]=s-'0';
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=m;j>=1;j--){
				if(!a[i][j]) c[i][j]=c[i][j+1]+1;
				else c[i][j]=0;
			}
		}
		for(int i=1;i<=m;i++){
			for(int j=n;j>=1;j--){
				if(!a[j][i]) f[j][i]=f[j+1][i]+1;
			}
		}
		dfsc();
		printf("%lld %lld\n",ansc,ansf);
	}
}

