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

template<typename T>
ostream& operator<<(ostream& ost, const vector<T>& a) {
	bool first = true;
	for (const T& x : a) {
		if (!first) ost << ",";
		ost << x, first = false;
	}
	return ost;
}

void debug_out() { cerr << "\n"; }

template<typename U, typename... T>
void debug_out(const U& x, const T&... args) {
	cerr << " " << x;
	debug_out(args...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) // debuger

constexpr int mod = 998244353;

void sub(int& x) {
	if (x >= mod) x -= mod;
}

template<typename T = int>
int power(int a, T x = mod - 2) {
	int res = 1;
	while (x) {
		if (x & 1) res = (long long) res * a % mod;
		x >>= 1;
		a = (long long) a * a % mod;
	}
	return res;
}

int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt, id;
	cin >> tt >> id;
	while (tt--) {
		int n, m, c, f;
		cin >> n >> m >> c >> f;
		vector<string> a(n);
		for (int i = 0; i < n; ++i) cin >> a[i];
		vector<vector<int>> cnt(n, vector<int>(m, 0));
		for (int i = 0; i < n; ++i) {
			int cur = 0;
			for (int j = m - 1; j >= 0; --j) {
				if (a[i][j] == '1') cur = 0;
				else cnt[i][j] = ++cur;
			}
		}
		int cntc = 0, cntf = 0;
		for (int j = 0; j < m; ++j) {
			int x = 0, y = 0, z = 0;
			for (int i = 0; i < n; ++i) {
				if (a[i][j] == '1') x = y = z = 0;
				else {
					sub(z += y);
					y = (long long) (cnt[i][j] - 1) * x % mod;
					if (i and a[i - 1][j] == '0') sub(y += mod - (long long) (cnt[i][j] - 1) * (cnt[i - 1][j] - 1) % mod);
					sub(x += cnt[i][j] - 1);
				}
				sub(cntc += y);
				sub(cntf += z);
			}
		}
		if (!c) cntc = 0;
		if (!f) cntf = 0;
		cout << cntc << ' ' << cntf << '\n';
	} 
}