#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int Mod = 998244353;
int n, m, c, f, T, id, a[2000][2000], ans_c, ans_f, cnt_rzero[2000][2000], cnt_dzero[2000][2000], cnt_sum_rzero[2000][2000], cnt_sum_cross_dzero[2000][2000];
int main() {
  freopen("plant.in", "r", stdin);
  freopen("plant.out", "w", stdout);
	scanf("%d %d", &T, &id);
	
	while (T--) {
		scanf("%d %d %d %d", &n, &m, &c, &f);
		ans_c = ans_f = 0;
		memset(cnt_rzero, 0, sizeof(cnt_rzero));
		memset(cnt_dzero, 0, sizeof(cnt_dzero));
		
		if (c == 0 && f == 0) {
			printf("0 0\n");
			continue;
		}
		
		for (int i = 1; i <= n; i++) {
			int j = 0;
			
			for (char ch = getchar(); j < m; ch = getchar())
				if (ch >= '0' && ch <= '9')
					a[i][++j] = ch - '0';
		}
//for (int i = 1; i <= n; i++)
//	for (int j = 1; j <= m; j++)
//		a[i][j] = 0;
			
		for (int i = 1; i <= n; i++)
			for (int j = m; j; j--)
				if (a[i][j] == 0)
					cnt_rzero[i][j - 1] = cnt_rzero[i][j] + 1;
		
		for (int j = 1; j <= m; j++)
			for (int i = n; i; i--)
				if (a[i][j] == 0)
					cnt_dzero[i - 1][j] = cnt_dzero[i][j] + 1;
		
		for (int j = 1; j <= m; j++)
			for (int i = n; i; i--)
				if (a[i][j] == 0) {
					cnt_sum_rzero[i - 1][j] = cnt_sum_rzero[i][j] + cnt_rzero[i][j];
					cnt_sum_cross_dzero[i - 1][j] = (cnt_sum_cross_dzero[i][j] + cnt_dzero[i][j] * cnt_rzero[i][j]) % Mod;
				}
					
		
		for (int x1 = 1; x1 <= n; x1++)
			for (int y0 = 1; y0 <= m; y0++) {
				if (a[x1][y0] || cnt_dzero[x1][y0] < 2 || cnt_rzero[x1][y0] == 0)
					continue;
				
				ans_c = (ans_c + cnt_sum_rzero[x1 + 1][y0] * cnt_rzero[x1][y0] % Mod) % Mod;
				ans_f = (ans_f + cnt_sum_cross_dzero[x1 + 1][y0] * cnt_rzero[x1][y0] % Mod) % Mod;
			}
		
		ans_c *= c;
		ans_f *= f;
		printf("%d %d\n", ans_c, ans_f);
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

