#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e3 + 10,MOD = 998244353;
int T,id,n,m,c,f;
LL a[N][N],pre[N][N],ansc,ansf;
bool mp[N][N];
int read() {
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-')	f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return x * f;
}
int main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T = read(),id = read();
	while(T --) {
		memset(a,0,sizeof(a));
		memset(pre,0,sizeof(pre));
		n = read(),m = read(),c = read(),f = read(),ansc = 0,ansf = 0;
		for(int i = 1;i <= n;i ++)
			for(int j = 1;j <= m;j ++) {
				char c;cin >> c;
				mp[i][j] = (c - '0') ^ 1;
			}
		if(!c && !f) {printf("0 0\n");continue;}
		for(int i = 1;i <= n;i ++)
			for(int j = m;j >= 1;j --)
				if(mp[i][j])	a[i][j] = a[i][j + 1] + 1;
		for(int j = 1;j <= m;j ++)
			for(int i = 1;i <= n;i ++)
				pre[i][j] = pre[i - 1][j] + a[i][j];
		for(int i = 1,j = 1;j < m;) {
			int l = i;
			while(!mp[l][j] && l <= n)	l ++;
			if(l > n) {i = 1,j ++;continue;}
			int r = l;
			while(mp[r + 1][j] && r <= n)	r ++;
			for(int k = l;k + 2 <= r;k ++)	ansc += a[k][j + 1] * (pre[r][j + 1] - pre[k + 1][j + 1]),ansc %= MOD;
			for(int k = l;k + 3 <= r;k ++) {
				LL sum = 0,cnt = r - k - 2;
				for(int q = k + 2;q + 1 <= r;q ++)	sum += cnt * a[q][j + 1],cnt --;
				ansf += a[k][j + 1] * sum,ansf %= MOD;
			}
			i = r + 1;
		}
		printf("%lld %lld\n",c * ansc,f * ansf);
	}
	return 0;
}