#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define int long long

using namespace std;

const int mod = 998244353;
const int M = 1000 + 10;

int T, id;
int n, m, c, f, ans_c, ans_f, sum_c, sum_f;

struct Point {
	int h, s;
	char ch;
} p[M][M];

int cnt;

inline void init ()
{
	for (int i = 0; i <= n + 1; ++ i)
		for (int j = 0; j <= m + 1; ++ j)
			p[i][j].ch = '1';
	ans_c = 0;
	ans_f = 0;
}

inline bool judge ()
{
	if (c == 0 && f == 0)
	{
		ans_c = 0;
		ans_f = 0;
		return true;
	}
	return false;
}

inline void solve ()
{
	scanf ("%lld %lld %lld %lld", &n, &m, &c, &f);
	if (judge () == true)
	{
		cout << 0 << " " << 0 << endl;
		return ;
	}
	init ();
	getchar ();
	for (int i = 1; i <= n; ++ i)
	{
		for (int j = 1; j <= m; ++ j)
		{
			p[i][j].ch = getchar ();
			if (p[i][j].ch == '0')
				p[i][j].h = 1, p[i][j].s = 1;
			else
				p[i][j].h = 0, p[i][j].s = 0;
		}
		getchar ();
	}		
	for (int i = 1; i <= n; ++ i)
		for (int j = m - 1; j >= 1; j --)
			if (p[i][j].ch == '0')
				p[i][j].h += p[i][j + 1].h;
	for (int j = 1; j <= m; ++ j)
		for (int i = n - 1; i >= 1; i --)
			if (p[i][j].ch == '0')
				p[i][j].s += p[i + 1][j].s;
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= m; ++ j)
		{
			if (p[i][j].s < 3 || p[i][j].h < 2 || p[i][j].ch == '1')
				continue;
			for (int k = i + 2; k <= n; ++ k)
			{
				if (p[k][j].ch == '1')
					break;
				ans_c = (ans_c + (p[i][j].h - 1) * (p[k][j].h - 1) % mod) % mod;
				ans_f = (ans_f + (p[i][j].h - 1) * (p[k][j].h - 1) * (p[k][j].s - 1) % mod) % mod;
			}
		}
	printf ("%lld %lld\n", (c * ans_c) % mod, (f * ans_f) % mod);
	return ;
}

signed main ()
{
	freopen ("plant.in", "r", stdin);
	freopen ("plant.out", "w", stdout);
	
	scanf ("%lld %lld", &T, &id);
	while (T --)
		solve ();
	
	return 0;
}