#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int mod=998244353;
void modp(int&x){
	x>=mod&&(x-=mod);
}
constexpr int max_n=2000,max_m=2000;
int a[max_n+2][max_m+2];
int ansc,ansf;
int b[max_n+1];
void solve(const int n){
	if(n<=2)
		return;
	int now=0;
	for(int i=3; i<=n; ++i){
		modp(now+=b[i-2]);
		// fprintf(stderr,"%d: %d %d\n",i,now,b[i]);
		ll t=now*ll(b[i])%mod;
		modp(ansc+=t);
		ansf=(ansf+t*(n-i))%mod;
	}
}
void test(){
	int n,m,c,f;
	scanf("%d%d%d%d",&n,&m,&c,&f);
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j){
			scanf("%1d",a[i]+j);
			a[i][j]=1-a[i][j];
		}
	for(int i=1; i<=n; ++i){
		a[i][m+1]=0;
		for(int j=m; j; --j)
			if(a[i][j])
				a[i][j]+=a[i][j+1];
	}
	ansc=0,ansf=0;
	for(int j=1; j<=m; ++j){
		int now=0;
		for(int i=1; i<=n; ++i){
			// fprintf(stderr,"%d %d: %d\n",i,j,a[i][j]);
			if(a[i][j])
				b[++now]=a[i][j]-1;
			else{
				solve(now);
				now=0;
			}
		}
		solve(now);
	}
	printf("%d %d\n",ansc*c,ansf*f);
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t;
	for(scanf("%d%*d",&t); t; test(),--t);
	return 0;
}