#include <bits/stdc++.h>
#define rep(i,j,k) for(int i = (j);i <= (k);i++)
#define per(i,j,k) for(int i = (j);i >= (k);i--)
#define eb emplace_back
#define pii pair <int,int>
#define mkp make_pair
#define ll long long
#define ull unsigned long long
#define mod 998244353
using namespace std;

void chkmin(int &x,int y){
	if(x > y) x = y;
}

void chkmax(int &x,int y){
	if(x < y) x = y;
}

void chkmin(ll &x,ll y){
	if(x > y) x = y;
}

void chkmax(ll &x,ll y){
	if(x < y) x = y;
}
int T,id;
int n,m,c,f;
char a[1005][1005];
int b[1005][1005];//ext

inline void add(ll &x,ll y){
	x += y;
	x %= mod;
	if(x < 0) x += mod;
}

void solve(){
	scanf("%d%d%d%d",&n,&m,&c,&f);
	rep(i,1,n){
		scanf("%s",a[i] + 1);
	}
	rep(i,1,n){
		b[i][m + 1] = 0;
		per(j,m,1){
			if(a[i][j] == '1')	b[i][j] = 0;
			else b[i][j] = b[i][j + 1] + 1;
		}
	}
	/*rep(i,1,n){
		rep(j,1,m){
			printf("%d ",b[i][j]);
		}
		printf("\n");
	}*/
	ll ans1 = 0,ans2 = 0,sum;
	rep(j,1,m){
		//printf("[%d]\n",j);
		for(int l = 1,r;l <= n;l = r + 1){
			r = l;
			if(a[l][j] == '1') continue;
			while(r + 1 <= n && a[r + 1][j] == '0') r++;
			//printf("%d %d\n",l,r);
			sum = 0;
			rep(i,l + 2,r){
				sum += b[i - 2][j] - 1;
				add(ans1,sum * (b[i][j] - 1));
				add(ans2,sum * (b[i][j] - 1) % mod * (r - i));
			}
		}
	}
	printf("%lld %lld\n",ans1 * c,ans2 * f);
}

int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while(T--) solve();
	return 0;
}
