#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

bool _jntm_u;

namespace AK {


typedef long long ll;
typedef double db;

#define rep(i, l, r) for(int i = l, i##end = r; i <= i##end; ++ i)
#define per(i, l, r) for(int i = l, i##end = r; i >= i##end; -- i)

template <class T>
inline void chmax(T &x,const T &y) {
	if(x < y) x = y;
}

template <class T>
inline void chmin(T &x, const T &y) {
	if(y < x) x = y;
}

inline int read() {
	int res = 0; char ch = getchar(); bool f = 1;
	for(; ch < '0' || ch > '9'; ch = getchar())
		if(ch == '-') f = 0;
	for(; ch >= '0' && ch <= '9'; ch = getchar())
		res = res * 10 + ch - '0';
	return f ? res : -res;
}

const int N = 1e3 + 15, P = 998244353;

char s[N][N];
ll dn[N][N], ri[N][N];
int n, m;
ll argc, argf, ansc, ansf;

inline ll poww(ll x, ll y = P - 2) {
	ll res = 1;
	for(; y; y >>= 1, x = x * x % P)
		if(y & 1) res = res * x % P;
	return res;
}

inline void madd(ll &x, ll y) {
	x += y;
	if(x >= P) x -= P;
}

inline ll mod(ll x) {
	return x >= P ? x - P : x;
}

void solve() {
	scanf("%d%d", &n, &m);
	scanf("%lld%lld", &argc, &argf);
	ansc = ansf = 0;
	rep(i, 1, n) {
		scanf("%s", s[i] + 1);
	}
	memset(dn, 0, sizeof(dn));
	memset(ri, 0, sizeof(ri));
	rep(i, 1, n) per(j, m, 1)
		ri[i][j] = s[i][j] == '0' ? ri[i][j + 1] + 1 : 0;
	per(i, n, 1) rep(j, 1, m)
		dn[i][j] = s[i][j] == '0' ? dn[i + 1][j] + 1 : 0;
	per(j, m, 1) {
		ll sum = 0, tmp;
		rep(i, 1, n) {
			if(s[i][j] == '1') {
				sum = 0;
				continue;
			}
			if(s[i - 1][j] == '0') {
				tmp = sum - (ri[i - 1][j] - 1);
				(ansc += 1ll * (ri[i][j] - 1) * tmp) %= P;
				(ansf += 1ll * (ri[i][j] - 1) * (dn[i][j] - 1) * tmp) %= P;
			}
			
			sum += ri[i][j] - 1;
		}
	}
	
	ansc = (ansc * argc) % P;
	ansf = (ansf * argf) % P;
	printf("%lld %lld\n", ansc, ansf);
}

void Main() {
	int T, Tp;
	scanf("%d", &T);
	scanf("%d", &Tp);
	while(T --) solve();
}

}

bool _jntm_v;

signed main() {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	//clock_t st = clock();
	AK :: Main();
	//cerr << "time = " << (clock() - st) * 1.0 / CLOCKS_PER_SEC << endl;
	//cerr << "space = " << (&_jntm_u - &_jntm_v) / 1048576.0 << endl;
	return 0;
}