#include <bits/stdc++.h>

using namespace std;

inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while (! isdigit(ch)){
		if (ch == '-')
			f = - f;
		ch = getchar();
	}
	while (isdigit(ch)){
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * f;
}

void write(int x){
	if (x < 0){
		putchar('-');
		write(- x);
		return;
	}
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + 48);
	return;
}

inline void writeln(int x){
	write(x);
	puts("");
	return;
}

inline void writesp(int x){
	write(x);
	putchar(' ');
	return;
}

const int MAXN = 2005, mod = 998244353;

int T, id, n, m, c, f;
int sum11[MAXN][MAXN], a[MAXN][MAXN], sumX[MAXN][MAXN], sumY[MAXN][MAXN], sum1[MAXN][MAXN], sum2[MAXN][MAXN];

inline void prep(){
	for (int i = 0; i <= n + 10; ++ i)
		for (int j = 0; j <= m + 10; ++ j)
			a[i][j] = sum11[i][j] = sumX[i][j] = sum1[i][j] = sumY[i][j] = sum2[i][j] = 0;
	return;
}

signed main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	T = read(), id = read();
	while (T --){
		n = read(), m = read(), c = read(), f = read();
		prep();
		for (int i = 1; i <= n; ++ i)
			for (int j = 1; j <= m; ++ j){
				char ch = getchar();
				while (ch != '0' && ch != '1')
					ch = getchar();
				if (ch == '1')
					a[i][j] = 1;
				else
					a[i][j] = 0;
			}
		for (int i = 1; i <= n; ++ i)
			for (int j = m - 1; j >= 1; -- j)
				if (a[i][j + 1] == 0 && a[i][j] == 0)
					sumX[i][j] = sumX[i][j + 1] + 1;
		for (int i = n - 1; i >= 1; -- i)
			for (int j = 1; j <= m; ++ j)
				if (a[i + 1][j] == 0 && a[i][j] == 0)
					sumY[i][j] = sumY[i + 1][j] + 1;
		for (int i = n; i >= 1; -- i)
			for (int j = 1; j <= m; ++ j)
				if (a[i][j] == 0)
					sum1[i][j] = sumX[i][j] + sum1[i + 1][j];
					
		for (int i = 1; i <= n; ++ i)
			for (int j = 1; j <= m; ++ j)
				if (a[i][j] ==0)
					sum11[i][j] = sumX[i][j] + sum11[i - 1][j];
		for (int i = 1; i <= n; ++ i)
			for (int j = 1; j <= m; ++ j)
				if (a[i][j] == 0)
					sum2[i][j] = sum11[i][j] + sum2[i - 1][j];
		int ansC = 0;
		for (int i = 1; i <= n; ++ i)
			for (int j = 1; j <= m; ++ j){
				if (a[i][j] == 1 || a[i + 1][j] == 1)
					continue;
				(ansC += (sumX[i][j] * sum1[i + 2][j]) % mod) %= mod;
			}
		writesp(ansC * c % mod);
		int ansF = 0;
		for (int i = 1; i <= n; ++ i)
			for (int j = 1; j <= m; ++ j){
				if (a[i][j] == 1 || sumX[i][j] == 0 || i + 2 > n || a[i + 1][j] == 1 || a[i + 2][j] == 1 || a[i + 3][j] == 1)
					continue;
				int x3 = i + sumY[i][j];
				int tot = (x3 - 1) - (i + 2) + 1;
				(ansF += ((sum2[x3 - 1][j] - sum2[i + 1][j]) - tot * sum11[i + 1][j]) * sumX[i][j] % mod) %= mod;
			}
		writeln(ansF * c % mod);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
