#include<bits/stdc++.h>
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
int read(){
	char c=getchar();
	int x=0,f=1;
	while(!isdigit(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(isdigit(c)){
		x=(x<<3)+(x<<1)+(c^48);
		c=getchar();
	}
	return f==1?x:~x+1;
}
int T,id;
int n,m,c,f;
char str[1010][1010];
int a[1010][1010];
const int mod=998244353;
int R[1010][1010];
int D[1010][1010];
int UC[1010][1010];
int UF[1010][1010];
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();
		memset(R,0,sizeof(R));
		memset(D,0,sizeof(D));
		memset(UC,0,sizeof(UC));
		memset(UF,0,sizeof(UF));
		for(int i=1;i<=n;++i){
			scanf("%s",str[i]+1);
			for(int j=1;j<=m;++j){
				a[i][j]=(str[i][j]-'0');
			}
		}
		for(int i=1;i<=n;++i){
			for(int j=m;j>=1;--j){
				if(a[i][j]==0) R[i][j]=R[i][j+1]+1;
				else R[i][j]=0;
			}
		}
		for(int i=n;i>=1;--i){
			for(int j=1;j<=m;++j){
				if(a[i][j]==0) D[i][j]=D[i+1][j]+1;
				else D[i][j]=0;
			}
		}
		int ansc=0,ansf=0;
		for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
				if(a[i][j]==0){
					UC[i][j]=UC[i-1][j]+(R[i][j]-1);
					UF[i][j]=UF[i-1][j]+(R[i][j]-1);
					if(i>2&&a[i-1][j]==0){
						(ansc+=1ll*(R[i][j]-1)*UC[i-2][j]%mod)%=mod;
						(ansf+=1ll*(D[i][j]-1)*UF[i-2][j]%mod*(R[i][j]-1)%mod)%=mod;
					}
				}
				else UC[i-1][j]=UF[i-1][j]=0;
			}
		}
		printf("%d %d\n",1ll*ansc*c%mod,1ll*ansf*f%mod);
	}
}