#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e3 + 10;
const int mod = 998244353;
int T, id;
int n, m, c, f;
char a[MAXN][MAXN];
int hang[MAXN][MAXN], lei[MAXN][MAXN];
int sum[MAXN][MAXN], tot[MAXN][MAXN];

void work()
{
	cin >> n >> m >> c >> f;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	for (int i = 0; i <= n + 1; i++)
		for (int j = 0; j <= m + 1; j++)
			hang[i][j] = lei[i][j] = sum[i][j] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = m; j >= 1; j--)
			if (a[i][j] == '0')
				hang[i][j] = hang[i][j + 1] + 1;
	for (int j = 1; j <= m; j++)
		for (int i = n; i >= 1; i--)
			if (a[i][j] == '0')
			{
				sum[i][j] = sum[i + 1][j] + hang[i][j] - 1;
				lei[i][j] = lei[i + 1][j] + 1;
				tot[i][j] = (tot[i + 1][j] + (hang[i][j] - 1) * (lei[i][j] - 1)) % mod;
			}
	int ansc = 0, ansf = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i + 1][j] == '0' && a[i][j] == '0' && a[i + 2][j] == '0')
			{
				ansc = (ansc + (hang[i][j] - 1) * sum[i + 2][j]) % mod;
				ansf = (ansf + (hang[i][j] - 1) * tot[i + 2][j]) % mod;
			}
	cout << ansc * c << ' ' << ansf * f << endl;
}

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