#include <bits/stdc++.h>
typedef long long LL;

const int MAXN = 1e3 + 5;
const LL P = 998244353;
int t, n, m, Copt, Fopt, r[MAXN][MAXN], a[MAXN][MAXN], Down[MAXN][MAXN];
LL ansC, ansF;

int Read()
{
	int sum = 0, fh = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) fh -= (ch == '-') << 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ 48);
	return sum * fh;
}

void Solve()
{
	n = Read(), m = Read(), Copt = Read(), Fopt = Read(); ansC = 0, ansF = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			char ch = getchar(); for (; ch != '1' && ch != '0'; ch = getchar()) ;
			a[i][j] = 1 - (ch - '0');
		}
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) Down[i][j] = r[i][j] = 0;
	for (int i = 1; i <= n; ++i) r[i][m] = a[i][m];
	for (int j = m - 1; j >= 1; --j)
		for (int i = 1; i <= n; ++i)
		{
			if (a[i][j] == 0) r[i][j] = 0;
			else r[i][j] = r[i][j + 1] + 1;
		}
	for (int j = 1; j <= m; ++j) Down[n][j] = a[n][j];
	for (int i = n - 1; i >= 1; --i)
		for (int j = 1; j <= m; ++j)
		{
			if (a[i][j] == 0) Down[i][j] = 0;
			else Down[i][j] = Down[i + 1][j] + 1;
		}
	for (int j = 1; j <= m; ++j)
	{
		LL x = 0, y = 0;
		for (int i = 1; i <= n; ++i)
		{
			x = r[i][j] - 1;
			if (a[i][j] == 0) { x = 0, y = 0; continue ; }
			ansC = (ansC + x * y % P) % P;
			ansF = (ansF + x * y % P * (Down[i][j] - 1) % P) % P;
			if (a[i - 1][j] == 1) y = (y + r[i - 1][j] - 1);
		}
	}
	printf("%lld %lld\n", Copt * ansC, Fopt * ansF);
}

int main()
{
	freopen("plant.in", "r", stdin); freopen("plant.out", "w", stdout);
	t = Read(); Read(); while (t--) Solve(); return 0;
}