#include <bits/stdc++.h>

const int MOD = 998244353;
enum int_t : int {};

int_t operator+(int_t a, int_t b)
{
	int r = (int)a + (int)b;
	if (r >= MOD)
		r -= MOD;
	return int_t(r);
}

int_t operator-(int_t a, int_t b)
{
	int r = (int)a - (int)b;
	if (r < 0)
		r += MOD;
	return int_t(r);
}

int_t operator*(int_t a, int_t b)
{
	int64_t r = (int64_t)a * (int64_t)b;
	return (int_t)(r % MOD);
}

int main()
{
#ifndef CM_DEBUG
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
#endif

	const int N = 1005;

	int T;
	scanf("%d%*d", &T);
	for (int i = 0; i < T; i++)
	{
		
		static char map[N][N];
		int n, m, wc, wf;
		scanf("%d%d%d%d", &n, &m, &wc, &wf);
		for (int i = 0; i < n; i++)
			scanf("%s", map[i]);

		static int r_last[N];
		std::fill_n(r_last, n, 0);

		int_t ans_c = (int_t)0;
		int_t ans_f = (int_t)0;
		for (int j = m - 1; j >= 0; j--)
		{
			int_t cd_c = (int_t)0;
			int_t cd_f = (int_t)0;
			int d_last = 0;
			for (int i = n - 1; i >= 0; i--)
			{
				if (map[i][j] == '0')
				{
					r_last[i] = r_last[i] + 1;
					d_last = d_last + 1;
					ans_c = ans_c + (int_t)(r_last[i] - 1) * cd_c;
					ans_f = ans_f + (int_t)(r_last[i] - 1) * cd_f;
					if (i + 1 < n && map[i + 1][j] == '0')
					{
						cd_c = cd_c + (int_t)(r_last[i + 1] - 1);
						cd_f = cd_f + (int_t)(r_last[i + 1] - 1) * (int_t)(d_last - 2);
					}
				}
				else
				{
					r_last[i] = 0;
					d_last = 0;
					cd_c = (int_t)0;
					cd_f = (int_t)0;
				}
			}
		}

		int_t o_c = (int_t)wc * ans_c;
		int_t o_f = (int_t)wc * ans_f;
		printf("%d %d\n", (int)o_c, (int)o_f);
	}

	return 0;
}
