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

