#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll P=998244353LL;
//!!! c and f
//!!! duo ce
ll n,m,c,f,a[1005][1005],sh[1005][1005],sl[1005][1005],ansc,ansf;
void solve(){
	scanf("%lld%lld%lld%lld\n",&n,&m,&c,&f);
	if(c==0&&f==0){
		printf("0 0\n");return;
	}
	ansc=0LL;ansf=0LL;
	for(int i=1;i<=n;i++){
		char s[1005];
		scanf("%s",s+1);
		for(int j=1;j<=m;j++){
			a[i][j]=s[j]-'0';
			sh[i][j]=sl[i][j]=0LL;
		}
	}//printf("3252");
	for(int i=1;i<=n;i++){
		for(int j=m;j>=1;j--){
			if(a[i][j]==0)sh[i][j]=sh[i][j+1]+1LL;
			else sh[i][j]=0LL;
		}
	}
	for(int j=1;j<=m;j++){
		for(int i=n;i>=1;i--){
			if(a[i][j]==0)sl[i][j]=sl[i+1][j]+1LL;
			else sl[i][j]=0LL;
		}
	}
	for(int j=1;j<=m;j++){
		ll sum=0LL,suml=0LL;
		for(int i=1;i<=n;i++){
			if(a[i][j]==1){
				sum=0LL;suml=0LL;continue;
			}
			//printf("   %lld %lld %lld\n",sum,sh[i][j],sl[i][j]);
			if(sh[i][j]>1){
				ansc=(ansc+sum*(sh[i][j]-1LL))%P;
				if(sl[i][j]>1){
					ansf=(ansf+sum*(sh[i][j]-1LL)*(sl[i][j]-1LL))%P;
				}
				sum+=suml;
				suml=sh[i][j]-1LL;	
			}
			else{
				sum+=suml;
				suml=0LL;
			}	
		}	
	}
	printf("%lld %lld\n",ansc*c%P,ansf*f%P);
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%d%d",&T,&id);
	while(T--)solve();
	return 0;
}
