#include <bits/stdc++.h>
#define rep(x, l, r) for (int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) a.begin(), a.end()
#define SZ(x) ((int)x.size())
using namespace std;

const int MAXN = 1005;
const int mod = 998244353;
int a[MAXN][MAXN], s[MAXN][MAXN], sum[MAXN][MAXN];
char st[MAXN];

int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	int T, id;
	scanf("%d%d", &T, &id);
	while(T--){
		int n, m, c, f;
		scanf("%d%d%d%d", &n, &m, &c, &f);
		rep(i, 1, n){
			scanf("%s", st);
			rep(j, 1, m) a[i][j] = st[j - 1] == '1';
		}
		clr(s, 0);
		clr(sum, 0);
		rep(j, 1, m){
			repd(i, n, 1){
				if(!a[i][j]) s[i][j] = s[i + 1][j] + 1;
			}
		}
		int ans1 = 0, ans2 = 0;
		repd(j, m, 1){
			int res1 = 0, res2 = 0;
			rep(i, 1, n){
				if(a[i][j]){
					res1 = 0, res2 = 0;
					continue;
				}
				sum[i][j] = sum[i][j + 1] + 1;
				ans1 = (ans1 + 1ll * res1 * (sum[i][j] - 1) % mod) % mod;
				ans2 = (ans2 + 1ll * res1 * (sum[i][j] - 1) * (s[i][j] - 1) % mod) % mod;
				res1 = res2;
				res2 = (res2 + sum[i][j] - 1) % mod;
			}
		}
		printf("%d %d\n", ans1 * c, ans2 * f);
	}
	return 0;
}