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

#define MOD 998244353LL

int Case,id;
bool a[1234][1234];
long long backit[1234][1234];
long long downit[1234][1234];
long long upit[1234][1234];
long long upall[1234][1234];

int main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&Case,&id);
	while (Case --> 0) {
		memset(a,1,sizeof a);
		memset(backit,0,sizeof backit);
		memset(downit,0,sizeof downit);
		memset(upit,0,sizeof upit);
		memset(upall,0,sizeof upall);
		long long cit = 0,fit = 0,c,f;
		int n,m;
		char x;
		scanf("%d%d%lld%lld",&n,&m,&c,&f);
		for (int i = 1; i<=n; ++i)
			for (int j=1; j<=m; ++j) {
				for (x = getchar(); x!='0' && x!='1'; x = getchar());
				a[i][j] = x^48;
			}
		for (int i=1; i<=n; ++i)
			for (int j=m; j; --j)
				if (a[i][j+1] || a[i][j])
					backit[i][j] = 0;
				else 
					backit[i][j] = backit[i][j+1]+1;
		for (int i=n; i; --i)			
			for (int j=1; j<=m; ++j)
				if (a[i][j])
					downit[i][j] = 0;
				else downit[i][j] = (downit[i+1][j] + backit[i+1][j])%MOD;
		for (int i=n; i; --i)		
			for (int j=1; j<=m; ++j)
				if (a[i+1][j] || a[i][j])
					upit[i][j] = upall[i][j] = 0;
				else upit[i][j] = upit[i+1][j]+1,
				upall[i][j] = (upall[i+1][j] + (backit[i][j]*upit[i][j])%MOD)%MOD;
		for (int i=1; i<=n; ++i)		
			for (int j=1; j<=m; ++j)
				cit = (cit + (backit[i][j] * downit[i+1][j])%MOD)%MOD;
		for (int i=1; i<=n; ++i)		
			for (int j=1; j<=m; ++j)
				fit = (fit+(backit[i][j] * upall[i+1][j])%MOD)%MOD;
		printf("%lld %lld\n",cit*c%MOD,fit*f%MOD);
	}
	return 0;
}
