#include<bits/stdc++.h>
#define RI register int
#define ll long long
#define mod 998244353
using namespace std;
int n,m,c,f,T,id;
int a[1010][1010];
char s;
ll ansc,ansf;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline void solve(int x,int y){
	if(a[x+1][y]==1||a[x][y+1]==1)return;
	ll tot=0,sum1=0,sum2=0,num=0;
	for(RI i=y+1;i<=m;i++){
		if(a[x][i]==0)tot++;
		else break;
	}
	for(RI i=x+2;i<=n;i++){
		if(a[i][y]==0){
			num=0;
			for(RI j=y+1;j<=m;j++){
				if(a[i][j]==0)num++;
				else break;
			}
			sum1+=num;
			if(a[i+1][y]==0&&(i+1)<=n){
				for(RI j=i+1;j<=n;j++){
					if(a[j][y]==0)sum2+=num;
					else break;
				}
			}
		}	
		else break;
	}
	ansc+=tot*sum1;
	ansf+=tot*sum2;
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read();id=read();
	while(T--){
		n=read();m=read();c=read();f=read();
		ansc=0;ansf=0;
		for(RI i=1;i<=n;i++)
			for(RI j=1;j<=m;j++)
				a[i][j]=0;
		for(RI i=1;i<=n;i++)
			for(RI j=1;j<=m;j++){
				cin>>s;
				if(s=='1')a[i][j]=1;
			}
		if(c==0&&f==0){
			printf("0 0\n");
			continue;
		}
		else{
			for(RI i=1;i<n;i++)
				for(RI j=1;j<m;j++)
					if(a[i][j]==0)solve(i,j);
			printf("%lld %lld\n",(c*ansc)%mod,(f*ansf)%mod);
		}
	}
	return 0;
}