/*
	NOIP RP++!!
	8:30 - 9:45
*/
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int mod = 998244353;
int T,id;
const int N = 1e3 + 10;
int mp[N][N];
typedef long long ll;
ll c,f;
ll mul(ll a,ll b){
	if(a == 0) return 0;
	ll t = 0;
	while(b){
		if(b & 1){
			t = (t + a) % mod;
		}
		a = (a << 1) % mod;
		b >>= 1;
	}
	return t;
}
struct node{
	int t;
	int start;
	node(int t1,int st){
		t = t1;
		start = st;
	}
};
vector <node> v1[N];
ll vc,vf;
ll line[N];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	for(int ii = 1;ii <= T;ii++){
		vc = vf = 0;
		scanf("%d%d",&n,&m);//nÐÐ mÁÐ 
		scanf("%lld%lld",&c,&f);
		if(c == 0 && f == 0){
			printf("0 0\n");
			continue;
		}
		memset(mp,0,sizeof(mp));
		getchar();
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= m;j++){
				char c;
				c =  getchar();
				mp[i][j] = c - '0';
			}
			getchar();
		}
		for(int i = 1;i <= m;i++){
			v1[i].clear();
		}
		for(int i = 1;i <= m;i++){
			int tag = 0;
			int start = 1;
			for(int j = 1;j <= n;j++){
				if(mp[j][i] == 1 && tag != 0){
					v1[i].push_back(node(tag,start));
					tag = 0;
				}
				if(mp[j][i] == 0){
					if(tag == 0) start = j;
					tag++;
				}
			}
			v1[i].push_back(node(tag,start));
		}
		memset(line,0,sizeof(line));
		for(int i = 1;i <= n;i++){
			if(mp[i][1] == 0){
				ll t = 1;
				while(mp[i][t] == 0 && t <= m) t++;
				t = t - 1;
				line[i] = t;
			}
		}
		for(int j = 1;j <= m;j++){
			if(j != 1){
				for(int i = 1;i <= n;i++){
					if(mp[i][j - 1] == 0){
						line[i]--;
					}
					else{
						if(mp[i][j] == 0){
							ll t = j;
							while(mp[i][t] == 0 && t <= m) t++;
							t = t - j;
							line[i] = t;
						}
					}
				}
			}
			for(int i = 0;i < v1[j].size();i++){
				int st = v1[j][i].start;
				int ed = v1[j][i].t + v1[j][i].start - 1;
				for(int k = st;k <= ed;k++){
					if(line[k] == 1) continue;
					for(int l = k + 2;l <= ed;l++){
						if(line[l] != 1){
							vc = (vc + mul(line[l] - 1,line[k] - 1)) % mod;
							if(l != ed) vf = (vf + mul(ed - l,mul(line[l] - 1,line[k] - 1))) % mod;
						}
					}
				}
			}
		}
		printf("%lld %lld\n",mul(c,vc),mul(f,vf));
	}
	return 0;
}
/* 
1 0
4 3 1 1
001
010
000
000
*/
