#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define foR(i,a,b) for(int i=(a);i>=(b);i--)
#define inf 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
const int N=1e3+5,MOD=998244353;
int a[N][N];
int h[N][N];//from each pos to the highest h[pos];
int n,m;
int T,id;
int sumc[N],vc,vf,c,f;
inline void solve(int l,int r,int pos) {
	int v=h[r][pos];
	int res=0;
	For(i,l,r-2) res+=(v-1)%MOD*(h[i][pos]-1)%MOD;
	sumc[pos]=(res)%MOD;
}
inline void solve() {
	memset(h,0,sizeof(h));
	memset(a,0,sizeof(a));
	memset(sumc,0,sizeof(sumc));
	vc=vf=0;
	scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
	For(i,1,n) For(j,1,m) {
		char ch;
		cin>>ch;
		a[i][j]=ch-'0';
	}
	if(c==0&&f==0) {puts("0 0");return;}
	For(i,1,n) foR(j,m,1) {
		if(!a[i][j]) h[i][j]=h[i][j+1]+1;
		else h[i][j]=0;
	}
	For(j,1,m) {
		int last=1,lf=0;
		For(i,1,n+1) {
			if(h[i][j]) lf++;
			if(h[i][j]>1) {
				vf=(vf+lf*sumc[j]%MOD)%MOD,vc+=sumc[j],sumc[j]=0,lf=0;
				solve(last,i,j);
			}
			if(!h[i][j]) vf=(vf+lf*sumc[j]%MOD)%MOD,vc+=sumc[j],sumc[j]=0,lf=0,last=i+1;
		}
	}
	For(i,1,m) vc=(vc+sumc[i])%MOD;
	if(f==0) {printf("%lld 0\n",vc);return;}
	printf("%lld %lld\n",vc*c%MOD,vf*f%MOD);
}
signed main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>id;
	while(T--) {
		solve();
	}
	return 0;
}
