#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
const int mod=998244353;

int n,m,c,f,a[N][N],r[N][N],d[N][N],sum[N];
void work() {
	memset(a,0,sizeof(a));
	memset(r,0,sizeof(r));
	memset(d,0,sizeof(d));
	cin>>n>>m>>c>>f;
	for (int i=1;i<=n;i++) {
		string s;
		cin>>s;
		for (int j=1;j<=m;j++) {
			a[i][j]=s[j-1]=='1';
		}
	}
	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;
			}
		}
	}
	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;
			}
		}
	}
	int ans1=0,ans2=0;
	for (int j=1;j<=m;j++) {
		memset(sum,0,sizeof(sum));
		for (int i=1;i<=n;i++) {
			if (a[i][j]==0) {
				sum[i]=sum[i-1]+max(r[i][j]-1,0);
			}
			if (i>=3&&a[i][j]==0&&a[i-1][j]==0&&a[i-2][j]==0) {
				int C=1LL*(r[i][j]-1)*sum[i-2]%mod;
				ans1=(ans1+C)%mod;
				ans2=(ans2+1LL*C*(d[i][j]-1))%mod;
			}
		}
	}
	ans1*=c,ans2*=f;
	cout<<ans1<<' '<<ans2<<"\n";
}

signed main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	
	ios::sync_with_stdio(false),cin.tie(0);
	cout.precision(10),cout.setf(ios::fixed);
	
	int T,id;
	cin>>T>>id;
	while (T--) {
		work();
	}
	
	return 0;
}
