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

typedef long long ll;

const int N = 1005, mod = 998244353;

int T, id, n, m, c, f, a[N];
char s[N][N];

void solve() {
	scanf("%d%d%d%d", &n, &m, &c, &f);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
	}
	int ansc = 0, ansf = 0;
	for (int i = 1; i <= n; i++) {
		a[i] = 0;
	}
	for (int j = m; j; j--) {
		int f0 = 0, f1 = 0, pre = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = s[i][j] == '0' ? a[i] + 1 : 0;
			int tmp = (ll)max(a[i] - 1, 0) * f0 % mod;
			ansc = (ansc + tmp) % mod;
			
			if (!a[i]) {
				f0 = f1 = 0;
			} else {
				f0 = (f0 + max(a[i - 1] - 1, 0)) % mod;
				f1 = (f1 + pre) % mod;
			}
			pre = tmp;
			(ansf += f1) %= mod;
		}
	}
	printf("%d %d\n", ansc, ansf);
}

int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	scanf("%d%d", &T, &id);
	while (T--) {
		solve();
	}
	return 0;
}