#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int mod = 998244353;
const int inv2 = (mod + 1) / 2;
long long id,n,m,c,f,ansc,ansf,sum[maxn][maxn],tmp[maxn],tot,pre[maxn];
char s[maxn][maxn];
inline int read()
{
	int x = 0,f = 1;char ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return f * x;
}
void clear()
{
	ansc = 0,ansf = 0;
	memset(s,0,sizeof(s));
	memset(sum,0,sizeof(sum));
}
void input()
{
	n = read(),m = read(),c = read(),f = read();
	for(int i = 1;i <= n;i++)
		scanf("%s",s[i] + 1);
}
void prefix()
{
	for(int i = 1;i <= n;i++)
		for(int j = m;j;j--)
			if(s[i][j] == '1')
				sum[i][j] = 0;
			else
				sum[i][j] = sum[i][j + 1] + 1;
}
void calc()
{
	long long res = 0;
	for(int i = 1;i <= tot;i++)
		pre[i] = pre[i - 1] + tmp[i];
	for(int i = 3;i <= tot;i++)
		res = (res + tmp[i] * pre[i - 2] % mod) % mod;
	ansc = (ansc + res) % mod;
	res = 0;
	for(int i = 3;i < tot;i++)
		res = (res + tmp[i] * pre[i - 2] % mod * (tot - i) % mod) % mod;
	ansf = (ansf + res) % mod;
}
void solve()
{
	for(int j = 1;j <= m;j++)
	{
		int las = 1;
		for(int i = 1;i <= n + 1;i++)
			if(i == n + 1||s[i][j] == '1')
			{
				tot = 0;
				for(int k = las;k < i;k++)
					tmp[++tot] = sum[k][j + 1];
				calc();
				las = i + 1;
			}
	}
}
void output()
{
	printf("%lld %lld\n",c * ansc % mod,f * ansf % mod);
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T = read();id = read();
	while(T--)
	{
		clear();
		input();
		prefix();
		solve();
		output();
	}
	return 0 ;
}
/*
NOIP 2022 RP++
*/

