#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1005;
const int MOD=998244353;
int T,id,n,m,c,f;
char s[N][N];
int line[N][N],row1[N][N],row2[N][N];
void PreSolve()
{
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=m;++j) {
			line[i][j]=0;
			row1[i][j]=0;
			row2[i][j]=0;
		}
	}
}
void PreSolveLine()
{
	for(int i=1;i<=n;++i) {
		int l=1,r=1;
		while(l<=m&&r<=m) {
			if(s[i][l]=='1') {
				++l;
				continue;
			}
			r=l;
			while(s[i][r]=='0'&&r<=m) {
				++r;
			}
			for(int j=r-2;j>=l;--j) {
				line[i][j]=line[i][j+1]+1;
			}
			l=r;
		}
	}
}
void PreSolveRowUp()
{
	for(int j=1;j<=m;++j) {
		int l=1,r=1;
		while(l<=n&&r<=n) {
			if(s[l][j]=='1') {
				++l;
				continue;
			}
			r=l;
			while(s[r][j]=='0'&&r<=n) {
				++r;
			}
			for(int i=l+2;i<r;++i) {
				row1[i][j]=(row1[i-1][j]+line[i-2][j])%MOD;
			}
			l=r;
		}
	}
}
void PreSolveRowDown()
{
	for(int j=1;j<=m;++j) {
		int l=1,r=1;
		while(l<=n&&r<=n) {
			if(s[l][j]=='1') {
				++l;
				continue;
			}
			r=l;
			while(s[r][j]=='0'&&r<=n) {
				++r;
			}
			for(int i=r-2;i>=l;--i) {
				row2[i][j]=row2[i+1][j]+1;
			}
			l=r;
		}
	}
}
void Cal()
{
	int C=0,F=0;
	for(int i=3;i<=n;++i) {
		for(int j=1;j<=m;++j) {
			C=(C+line[i][j]*row1[i][j]%MOD)%MOD;
			F=(F+line[i][j]*row1[i][j]*row2[i][j]%MOD)%MOD;
		}
	}
	cout<<C*c%MOD<<" "<<F*f%MOD<<endl;
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>id;
	while(T--) {
		cin>>n>>m>>c>>f;
		PreSolve();
		for(int i=1;i<=n;++i) {
			scanf("%s",s[i]+1);
		}
		PreSolveLine();
		PreSolveRowUp();
		PreSolveRowDown();
		Cal();
	}
	return 0;
}
