#include <bits/stdc++.h>

typedef long long ll;
const int MOD = 998244353;
const int N = 1e3 + 10;

char str[N][N];
int r[N][N], d[N][N];
void solve() {
	memset(str, 0, sizeof(str));
	memset(r, -1, sizeof(r));
	memset(d, -1, sizeof(d));
	int n, m, c, f;
	scanf("%d%d%d%d", &n, &m, &c, &f);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", str[i] + 1);
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = m; j >= 1; --j) {
			if (str[i][j] == '0') r[i][j] = r[i][j + 1] + 1;
			else r[i][j] = -1;
		}
	}
	for (int i = n; i >= 1; --i) {
		for (int j = 1; j <= m; ++j) {
			if (str[i][j] == '0') d[i][j] = d[i + 1][j] + 1;
			else d[i][j] = -1;
		}
	}
	ll ansc = 0, ansf = 0;
	for (int j = 1; j <= m; ++j) {
		ll sum = 0;
		for (int i = 2; i <= n; ++i) {
			if (str[i][j] == '1' || str[i - 1][j] == '1') {
				sum = 0;
				continue;
			}
			ansc = (ansc + r[i][j] * sum) % MOD;
			ansf = (ansf + r[i][j] * sum % MOD * d[i][j]) % MOD;
			sum = (sum + r[i - 1][j]) % MOD;
		}
	}
	printf("%lld %lld\n", c * ansc % MOD, c * ansf % MOD);
	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;
}