#include<iostream>
#include<cstdio>
using namespace std;
const int N=1005;
const int MOD=998244353;
int n,m,c,f;
char s[N][N];
int r[N][N],d[N][N];
int sumr[N][N];
long long sumdr[N][N];
void solve()
{
	scanf("%d%d%d%d",&n,&m,&c,&f);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		r[i][m+1]=m+1;
		for(int j=m;j>=1;j--)
			if(s[i][j]=='1') r[i][j]=j;
			else r[i][j]=r[i][j+1];
	}
	for(int j=1;j<=m;j++)
	{
		d[n+1][j]=n+1;
		for(int i=n;i>=1;i--)
			if(s[i][j]=='1') d[i][j]=i;
			else d[i][j]=d[i+1][j];
	}
	for(int j=1;j<=m;j++)
	{
		sumr[n+1][j]=sumdr[n+1][j]=0;
		for(int i=n;i>=1;i--)
			if(s[i][j]=='1') sumr[i][j]=0;
			else sumr[i][j]=sumr[i+1][j]+r[i][j]-j-1,sumdr[i][j]=sumdr[i+1][j]+(long long)(r[i][j]-j-1)*(d[i][j]-i-1);
	}
//	for(int i=1;i<=n;i++)
//	{
//		
//		for(int j=1;j<=m;j++)
//			cerr<<sumr[i][j]<<" ";cerr<<"\n";
//	}
	int ansc=0,ansf=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='0')
			{
				if(i+2<=d[i][j]) ansc=(ansc+(long long)(r[i][j]-j-1)*(sumr[i+2][j]-sumr[d[i][j]][j]))%MOD;
				if(i+3<=d[i][j]) ansf=(ansf+(long long)(r[i][j]-j-1)*(sumdr[i+2][j]-sumdr[d[i][j]-1][j]))%MOD; 
			}
	ansc=(long long)ansc*c%MOD,ansf=(long long)ansf*f%MOD;
	printf("%d %d\n",ansc,ansf);
	return;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%d%d",&T,&id);
	while(T--)
		solve();
	return 0;
}