#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], d[N][N];
int T, subt, n, m, vc, vt, ans1, ans2;

int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.ans", "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++) {
			for (int j = 1; j <= m; j++) {
				a[i][j] = a[i][j - 1] + (c[i][j] - '0');
				b[i][j] = b[i - 1][j] + (c[i][j] - '0');
			}
		}
		for (int j = 1; j <= m; j++) {
			d[n + 1][j] = 0;
			for (int i = n; i >= 1; i--) {
				if (c[i][j] == '1') d[i][j] = 0;
				else d[i][j] = d[i + 1][j] + 1;
			}
		}
		for (int y = 1; y <= m; y++) {
			for (int l = 1; l <= n; l++) {
				for (int r = l + 2; r <= n; r++) {
					if (b[r][y] != b[l - 1][y]) break;
					int cnt = 0;
					for (int y1 = y + 1; y1 <= m; y1++) {
						if (a[l][y1] != a[l][y - 1]) break;
						for (int y2 = y + 1; y2 <= m; y2++) {
							if (a[r][y2] != a[r][y - 1]) break;
							++cnt;
						}
					}
					ans1 = add(ans1, cnt);
					ans2 = add(ans2, mul(cnt, d[r + 1][y]));
				}
			}
		}
		ans1 *= vc; ans2 *= vt;
		printf("%d %d\n", ans1, ans2);
	}
	return 0;
}