#include <bits/stdc++.h>

using namespace std;

const int P = 998244353;
int a[1005][1005];
int R[1005][1005];
int D[1005][1005];

int mul(const int &x, const int &y) {
	return 1ll * x * y % P;
}
int add(const int &x, const int &y) {
	return (x + y >= P) ? (x + y - P) : (x + y);
}

void solve() {
	int n, m, c, f;
	cin >> n >> m >> c >> f;
	memset(a, -1, sizeof a);
	memset(R, 0, sizeof R);
	memset(D, 0, sizeof D);

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			if (c == '1') a[i][j] = 1;
			else a[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = m; j >= 1; j--) {
			if (a[i][j] == 0)
				R[i][j] = R[i][j + 1] + 1;
			else 
				R[i][j] = 0;
		}
	}
	for (int j = 1; j <= m; j++) {
		for (int i = n; i >= 1; i--) {
			if (a[i][j] == 0) {
				D[i][j] = D[i + 1][j] + 1;
			} else {
				D[i][j] = 0;
			}
		}
	}
	int ansc = 0, ansf = 0;
	for (int j = 1; j <= m; j++) {
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i][j] == 0 && a[i - 1][j] == 0) {
				ansc = add(ansc, mul(sum, R[i][j + 1]));
				if (a[i + 1][j] == 0)
					ansf = add(ansf, mul(sum, mul(R[i][j + 1], D[i + 1][j])));
			}
			if (a[i - 1][j] == 0 && a[i][j] == 0)
				sum = add(sum, R[i - 1][j + 1]);
			else sum = 0;
		}
	}
	cout << c * ansc << " " << f * ansf << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	int t, id;
	cin >> t >> id;
	while (t--) {
		solve();
	}
	return 0;
}