#include <bits/stdc++.h>
namespace Qiaoqia { 
constexpr int N = 1005, P = 998244353;

int a[N][N], r[N][N];

void solve() {
	int n, m, c, f;
	std::cin >> n >> m >> c >> f;
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= m; j++) {
			char ch;
			std::cin >> ch;
			a[i][j] = (ch == '1' ? 0 : 1);
		}
	for (int i = 1; i <= n; i++)
		for (int j = m; j >= 1; j--) 
			if (a[i][j] == 0) r[i][j] = 0;
			else r[i][j] = r[i][j + 1] + 1;
	int ansc = 0, ansf = 0;
	for (int j = 1; j <= m; j++) {
		int sumr = 0, sumc = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i][j] == 0) { sumr = sumc = 0; continue; }
			ansf = (ansf + sumc) % P;
			if (r[i][j] > 0) {
				ansc = (ansc + 1ll * (r[i][j] - 1) * sumr % P) % P;
				sumc = (sumc + 1ll * (r[i][j] - 1) * sumr % P) % P;
			}
			if (i >= 2 && a[i - 1][j])
				sumr = (sumr + r[i - 1][j] - 1) % P;
		}
	}
	std::cout << ansc * c << ' ' << ansf * f << '\n';
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) 
			r[i][j] = 0, a[i][j] = 0;
}

void main() {
	int T, id;
	std::cin >> T >> id;
	while (T--) solve();
}
}
void _() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }
int main() { void IO(); IO(); _(); Qiaoqia::main(); }
void IO() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
}

// checklist completed at 0031K
