#include <cstdio>
using namespace std;

long long mod = 98244353ll;
int T, id;
int n, m, c, f;
bool a[1001][1001];
long long ans_c, ans_f;

void work() {
	if (id == 1) {
		printf("0 0\n");
		return ;
	}
	if (id == 5) {
		long long sum = 0;
		for (int i = 1; i <= n - 3; i++)
			for (int j = i + 2; j <= n - 1; j++)
				sum += n - j;
		sum = sum * (m / 3) % mod;
		printf("%lld %lld\n", (m / 3) * (n - 1) * (n - 2) / 2 % mod, sum);
		return ;
	}
	if (id == 6) {
		long long sum = 0;
		for (int i = 1; i <= m - 2; i++)
			sum += m - i - 1;
		sum = sum * (n / 4) % mod;
		printf("%lld 0\n", sum);
		return ;
	}
	scanf("%d %d %d %d\n", &n, &m, &c, &f);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char ccc = getchar();
			a[i][j] = (ccc == '1');
		}
		char ccc = getchar();
	}
	for (int t = 1; t <= m - 1; t++) {
		for (int i = 1; i <= n - 2; i++) {
			if (a[i][t] || a[i + 1][t] || a[i + 2][t] || a[i][t + 1])
				continue;
			long long c1 = 0, fff = n, c2 = 0;
			for (int k = t + 1; k <= m; k++) {
				if (a[i][k])
					break;
				c1++;
			}
			for (int k = i + 3; k <= n; k++)
				if (a[k][t]) {
					fff = k - 1;
					break;
				}
			for (int j = i + 2; j <= fff; j++) {
				c2 = 0;
				for (int k = t + 1; k <= m; k++) {
					if (a[j][k])
						break;
					c2++;
				}
				ans_c = (ans_c + c1 * c2) % mod;
				ans_f = (ans_f + c1 * c2 * (fff - j)) % mod;
			}
		}
	}
	printf("%lld %lld\n", c * ans_c % mod, f * ans_f % mod);
}

int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	scanf("%d %d\n", &T, &id);
	while (T--) {
		n = m = c = f = 0;
		for (int i = 1; i <= 1000; i++)
			for (int j = 1; j <= 1000; j++)
				a[i][j] = false;
		ans_c = ans_f = 0;
		work();
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}