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

typedef long long ll;

const int MAX_N = 1010;
const int MOD = 998244353;

int T, id;
int n, m, C, F;
bool mat[MAX_N][MAX_N];
ll hs[MAX_N][MAX_N], ls[MAX_N][MAX_N], fhs[MAX_N][MAX_N], fls[MAX_N][MAX_N];
ll ansc, ansf;

void read(int &x){
	char c = getchar(); x = 0;
	while (!isdigit(c)) c = getchar();
	while ( isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
	return;
}

int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	read(T); read(id);
	while (T--){
		memset(hs, 0, sizeof(hs));
		memset(ls, 0, sizeof(ls));
		memset(fhs, 0, sizeof(fhs));
		memset(fls, 0, sizeof(fls));
		memset(mat, 0, sizeof(mat));
		ansc = ansf = 0;
		read(n); read(m); read(C); read(F);
		//printf("%d %d %d %d\n", n, m, C, F);
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				char c; cin >> c;
				mat[i][j] = c - '0';
			}
		}
		for (int i = n; i >= 1; i--){
			for (int j = m; j >= 1; j--){
				if (!mat[i][j]){
					hs[i][j] = hs[i][j + 1] + 1;
					fhs[i][j] = fhs[i + 1][j] + 1;
				} 
				//printf("%lld ", hs[i][j]);
			}
		}
//		for (int i = 1; i <= n; i++){
//			for (int j = 1; j <= m; j++){
//				printf("i = %d j = %d hs = %lld\n", i, j, hs[i][j]);
//			}
//		}
		for (int i = n; i >= 1; i--){
			for (int j = 1; j <= m; j++){
				if (mat[i][j]){
					ls[i + 1][j] = 0;
					continue;
				}
				ansc = (ansc + ls[i + 2][j] * (hs[i][j] - 1) % MOD) % MOD;
				ls[i][j] = ls[i + 1][j] + hs[i][j] - 1;
				//printf("i = %d j = %d %lld * %lld = %lld\n", i, j, ls[i + 2][j], (hs[i][j] - 1), ls[i + 2][j] * (hs[i][j] - 1));
			}
		}
		for (int i = n; i >= 1; i--){
			for (int j = 1; j <= m; j++){
				if (mat[i][j]){
					fls[i + 1][j] = 0;
					continue;
				} 
				ansf = (ansf + fls[i + 2][j] * (hs[i][j] - 1) % MOD) % MOD;
				fls[i][j] = (fls[i + 1][j] + (hs[i][j] - 1) * fhs[i + 1][j] % MOD) % MOD;
				//printf("i = %d j = %d %lld * %lld = %lld\n", i, j, fls[i + 2][j], (hs[i][j] - 1), fls[i + 2][j] * (hs[i][j] - 1));
			}
		}
		printf("%lld %lld\n", ansc * C, ansf * F);
	}
//	for (int i = 1; i <= n; i++){
//		for (int j = 1; j <= m; j++){
//			printf("%u", mat[i][j]);
//		}
//		puts("");
//	}
	return 0;
}
