#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int T, id, n, m, p_c, p_f, ansc, ansf;
char a[1010][1010];
int rt[1010][1010], dn[1010][1010];
vector<pair<int, int>> ok[1010];
inline int Mod(int x){
	return x >= mod ? x - mod : x;
}
int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	scanf("%d%d", &T, &id);
	while(T--){
		scanf("%d%d%d%d", &n, &m, &p_c, &p_f);
		if(p_c == 0 && p_f == 0){
			puts("0 0");
			continue;
		}
		ansc = ansf = 0;
		memset(rt, 0, sizeof(rt));
		memset(dn, 0, sizeof(dn));
		for(int i = 0; i < m; i++) ok[i].clear();
		for(int i = 0; i < n; i++){
			scanf("%s", a[i]);
			a[i][m] = '1';
			int cnt = 0;
			for(int j = 0; j <= m; j++){
				if(a[i][j] == '0') cnt++;
				else if(cnt){
					for(int k = 1; k <= cnt; k++){
						rt[i][j - k] = k;
					}
					cnt = 0;
				}
			}
		}
		for(int i = 0; i <= m; i++) a[n][i] = '1';
		for(int j = 0; j < m; j++){
			int cnt = 0;
			for(int i = 0; i <= n; i++){
				if(rt[i][j] >= 1) cnt++;
				else if(cnt){
					for(int k = 1; k <= cnt; k++){
						dn[i - k][j] = k;
					}
					cnt = 0;
				}
			}
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m - 1; j++){
				if(rt[i][j] > 1){
					ok[j].emplace_back(make_pair(i, rt[i][j] - 1));
				}
			}
		}
		for(int j = 0; j < m - 1; j++){
			for(int k = 0; k < (int)ok[j].size() - 1; k++){
				for(int l = k + 1; l < (int)ok[j].size(); l++){
					if(ok[j][l].first - ok[j][k].first >= dn[ok[j][k].first][j]) break;
					if(ok[j][l].first - ok[j][k].first <= 1) continue;
					ansc = Mod(ansc + 1ll * ok[j][k].second * ok[j][l].second % mod);
					ansf = Mod(ansf + 1ll * ok[j][k].second * ok[j][l].second % mod * (dn[ok[j][l].first][j] - 1) % mod);
				}
			}
		}
		printf("%d %d\n", ansc * p_c, ansf * p_f);
	}
	return 0;
}
/*
被你发现了，嘻嘻 
//freopen
freeopen
feropen
freopen("plant.in", "w", stdout);
freopen("plant.out", "r", stdin);

有点暴力的写法，复杂度O(n^3)，手造最大点跑10.5s 
期望得分[70,100] 
*/
