#include<cstring>
#include<cstdio>
#include<set>
#define Re register
#define LL long long
using namespace std;
const int N = 1000 + 10;
const int P = 998244353;
set<LL> line[N];
set<LL> row[N];
set<LL> able[N];
LL l[N][N], r[N][N], sum[N][N], sum1[N][N];
char mp[N][N];
LL T, id, n, m, c, f, ansc, ansf;
inline LL read() {
	LL s = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
	return s * f;
}
inline void write(LL x) {
	if (x < 0) putchar('-'), x = ~(x - 1);
	int s[50], top = 0;
	while (x) s[++top] = x % 10, x /= 10;
	if (!top) s[++top] = 0;
	while (top) putchar(s[top--] + '0');
}
inline void Clear() {
	for (Re int i = 1; i <= n; ++i) row[i].clear();
	for (Re int i = 1; i <= m; ++i) line[i].clear();
	for (Re int i = 1; i <= m; ++i) able[i].clear();
	memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); memset(mp, 0, sizeof(mp)); memset(sum, 0, sizeof(sum)); memset(sum1, 0, sizeof(sum1));
	n = m = c = f = ansc = ansf = 0;
}
int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	T = read(), id = read();
	while (T--) {
		Clear();
		n = read(), m = read(), c = read(), f = read();
		for (Re int i = 1; i <= n; ++i) scanf ("%s", mp[i] + 1);
		for (Re int i = 1; i <= n; ++i) for (Re int j = 1; j <= m; ++j) if (mp[i][j] == '1') line[j].insert(i), row[i].insert(j), sum[i][j] = 1;
		for (Re int j = 1; j <= m; ++j) for (Re int i = 1; i <= n; ++i) sum[i][j] += sum[i - 1][j];
		for (Re int i = 1; i <= n; ++i)
			for (Re int j = 1; j <= m; ++j) {
				if (mp[i][j] == '0' && row[i].upper_bound(j) != row[i].end()) r[i][j] = *row[i].upper_bound(j) - j - 1;
				else if (mp[i][j] == '0' && row[i].upper_bound(j) == row[i].end()) r[i][j] = m - j;
				if (mp[i][j] == '0' && line[j].upper_bound(i) != line[j].end()) l[i][j] = *line[j].upper_bound(i) - i - 1;
				else if (mp[i][j] == '0' && line[j].upper_bound(i) == line[j].end()) l[i][j] = n - i;
				if (r[i][j]) able[j].insert(i);
			}
		for (Re int j = 1; j <= m; ++j) for (Re int i = 1; i <= n; ++i) sum1[i][j] = sum1[i - 1][j] + r[i][j];
		for (Re int j = 1; j <= m; ++j) {
			int p = 0;
			for (Re int i = 1; i <= n; ++i) {
				if (mp[i][j] == '1') p = i;
				if (p + 1 == i) continue;
				ansc = (ansc + (sum1[i - 2][j] - sum1[p][j]) * r[i][j] % P) % P, ansf = (ansf + (sum1[i - 2][j] - sum1[p][j]) * l[i][j] * r[i][j] % P) % P;
			}
		}
		write(c * ansc % P), putchar(' '), write(f * ansf), putchar('\n');
	}
	return 0;
}
/*
Akshay bless me
*/