#include <bits/stdc++.h>
#define forn(i,s,t) for(int i=(s); i<=(t); ++i)
#define form(i,s,t) for(int i=(s); i>=(t); --i)
#define rep(i,s,t) for(int i=(s); i<(t); ++i)
typedef long long i64;
using namespace std;
const int Mod = 998244353;
struct mint {
	int r;
	mint() {}
	mint(int _r) : r(_r) {}
	inline friend mint operator + (const mint& A, const mint& B) {
		return mint((A.r + B.r >= Mod) ? (A.r + B.r - Mod) : (A.r + B.r));
	}
	inline friend mint operator - (const mint& A, const mint& B) {
		return A + mint(Mod - B.r);
	}
	inline friend mint operator * (const mint& A, const mint& B) {
		return mint(1ll * A.r * B.r % Mod);
	}
	inline friend mint& operator += (mint& A, const mint& B) {
		return A = A + B;
	}
	inline friend mint& operator -= (mint& A, const mint& B) {
		return A = A - B;
	}
	inline friend mint& operator *= (mint& A, const mint& B) {
		return A = A * B;
	}
	inline friend mint q_pow(mint p, int k = Mod - 2) {
		mint r = 1;
		for (; k; k >>= 1, p *= p) (k & 1) && (r *= p, 0);
		return r;
	}
};
const int N = 1e3 + 3;
int n, m, c, f, r[N][N], d[N][N];
char s[N][N]; mint preC[N][N], preF[N][N];
mint ansC, ansF;
inline void init() {
	forn (i, 1, n) forn (j, 1, m) r[i][j] = d[i][j] = 0;
	forn (i, 1, n) forn (j, 1, m) preC[i][j] = preF[i][j] = 0;
	ansC = ansF = 0;
}
inline void print() {
	if (c) cout << ansC.r << ' ';
	else cout << 0 << ' ';
	if (f) cout << ansF.r << '\n';
	else cout << 0 << '\n';
}
inline void solve1() {
	forn (t, 1, m) forn (i, 1, n) {
		if (!s[i][t] && !s[i + 1][t]) forn (j, i + 2, n) {
			if (s[j][t]) break ;
			ansC += mint(max(0, r[i][t] - 1)) * mint(max(0, r[j][t] - 1)), 
			ansF += mint(max(0, r[i][t] - 1)) * mint(max(0, r[j][t] - 1)) * mint(max(0, d[j][t] - 1));
		}
	}
	print();
}
inline void solve2() {
	form (i, n, 1) form (j, m, 1) if (!s[i][j]) {
		preC[i][j] = preC[i + 1][j] + mint(max(0, r[i][j] - 1));
		preF[i][j] = preF[i + 1][j] + mint(max(0, r[i][j] - 1)) * mint(max(0, d[i][j] - 1));
	}
	forn (t, 1, m) forn (i, 1, n) 
		if (!s[i][t] && !s[i + 1][t]) 
			ansC += mint(max(0, r[i][t] - 1)) * preC[i + 2][t], 
			ansF += mint(max(0, r[i][t] - 1)) * preF[i + 2][t];
	print();
}
inline void solve() {
	cin >> n >> m >> c >> f;
	forn (i, 1, n) cin >> (s[i] + 1);
	forn (i, 1, n) forn (j, 1, m) s[i][j] -= '0';
	form (i, n, 1) form (j, m, 1) if (!s[i][j]) r[i][j] = r[i][j + 1] + 1, d[i][j] = d[i + 1][j] + 1;
	if (n <= 500 && m <= 500) solve1();
	else solve2();
}
int Trd, id;
int main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
//	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> Trd >> id;
	while (Trd--) init(), solve();
	return 0;
}