#include <bits/stdc++.h>

using namespace std;

#define Mod 998244353

 int read(){
	int AK = 1, IOI = 0;
	char ch = 0;
	while (ch < '0' || ch > '9'){
		AK = ch =='-'?-1:1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0'){
		IOI = (IOI << 3) + (IOI << 1);
		IOI += ch - 48;
		ch = getchar();
	}
	return AK * IOI;
}

const int Maxx = 1005;

int a[Maxx][Maxx];
long long lie_num[Maxx][Maxx];
long long hang_num[Maxx][Maxx];
long long C_ans;
long long F_ans;
//string s;
int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);

	int T = read(), IDD = read();
	while (T --){
		int n = read(), m = read();
//		printf("%d\n", n);
		long long num_c = read(), num_f = read();
		for (int i = 1; i <= n; ++ i){
			char ch = getchar();
//			cout << s;
			for (int j = 1; j <= m; ++ j){
				while (ch != '0' && ch != '1'){
					ch = getchar();
				}
				if (ch == '1'){
					a[i][j] = 1;
				} else{
					a[i][j] = 0;
				}
				ch = getchar();
			}
		}
//		printf("YES");
		memset(hang_num, 0, sizeof(hang_num));
		for (int i = 1; i <= n; ++ i){
			for (int j = m; j >= 1; --j){
				if (a[i][j] == 0){
					hang_num[i][j] = hang_num[i][j + 1] + 1;
				}
			}
		}
		memset(lie_num, 0, sizeof(lie_num));
		for (int j = 1; j <= m; ++ j){
			for (int i = n; i >= 1; -- i){
				if (a[i][j] == 0){
					lie_num[i][j] = lie_num[i + 1][j] + 1;
				}
			}
		}
//		printf("YES");
		C_ans = 0;
		F_ans = 0;
		for (int i = 1; i <= n; ++ i){
			for (int j = 1; j <= m; ++ j){
				hang_num[i][j] --;
				lie_num[i][j] --;

			}
		}
		for (int i = 1; i <= n - 2; ++ i){
			for (int j = 1; j <= m; ++ j){
				if (a[i][j] == 0 && hang_num[i][j] != 0 && lie_num[i][j] >= 2){
					for (int k = i + 2; k <= i + lie_num[i][j]; ++ k){
//						if (a[k][j] != 0){
//							break;
//						}	
						C_ans = (C_ans + (hang_num[i][j]) * (hang_num[k][j])) % Mod;
						F_ans = (F_ans + ((hang_num[i][j]) * (hang_num[k][j])) * (lie_num[k][j])) % Mod;
					}
				}
			}
		}
		C_ans = (C_ans * num_c) % Mod;
		F_ans = (F_ans * num_f) % Mod;
		printf("%lld %lld\n", C_ans, F_ans);
	}	
}