#include <bits/stdc++.h>
using namespace std;

template <typename T>
inline void read(T &f) {
	f = 0; int fu = 0; char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fu = 1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		f = f * 10 + c - '0';
		c = getchar();
	}
	if (fu) f = -f;
}

const int md = 998244353;

inline int add(int x, int y) {
	if (x + y >= md) return x + y - md;
	return x + y;
}

inline int sub(int x, int y) {
	if (x < y) return x - y + md;
	return x - y;
}

inline int mul(int x, int y) { return 1ull * x * y % md; }

inline int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		y >>= 1; x = mul(x, x);
	}
	return ans;
}

const int N = 1005;

char c[N][N];
int a[N][N], b[N][N];
int T, subt, n, m, vc, vt, ans1, ans2;

int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	read(T); read(subt);
	while (T--) {
		read(n); read(m); read(vc); read(vt);
		ans1 = ans2 = 0;
		for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
		for (int i = 1; i <= n; i++) {
			int val = 0;
			for (int j = m; j >= 1; j--) {
				if (c[i][j] == '1') {
					val = 0;
				} else {
					++val;
				}
				a[i][j] = val;
			}
		}
		for (int j = 1; j <= m; j++) {
			int val = 0;
			for (int i = n; i >= 1; i--) {
				if (c[i][j] == '1') {
					val = 0;
				} else {
					++val;
				}
				b[i][j] = val;
			}
		}
		for (int j = 1; j <= m; j++) {
			int sum = 0;
			for (int i = 1; i <= n - 2; i++) {
				if (c[i][j] == '1') {
					sum = 0;
				} else {
					sum += (a[i][j] - 1);
					if (c[i + 1][j] == '0' && c[i + 2][j] == '0') {
						ans1 = add(ans1, mul(sum, a[i + 2][j] - 1));
						ans2 = add(ans2, mul(mul(sum, a[i + 2][j] - 1), b[i + 2][j] - 1));
					}
				}
			}
		}
		ans1 *= vc; ans2 *= vt;
		printf("%d %d\n", ans1, ans2);
	}
	return 0;
}