#include <bits/stdc++.h>

#define int long long

using namespace std;

const int maxn = 1e3 + 50;
const int mod  = 998244353;

inline int add (int x, int y) { return (x + y) % mod; }
inline int mul (int x, int y) { return x * y % mod; }

int n, m, c, f;
char a[maxn][maxn];

int rht[maxn][maxn], rd[maxn][maxn], line[maxn];

inline void init ()
{
	memset (rht,  0, sizeof rht );
	memset (rd,   0, sizeof rd  );
	memset (line, 0, sizeof line);
}

signed main ()
{
	ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
	freopen ("plant.in", "r", stdin);
	freopen ("plant.out", "w", stdout);
	
	int T, id; cin >> T >> id;
	while (T--)
	{
		init ();
		
		cin >> n >> m >> c >> f;
		for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j];
		
		for (int i = n; i >= 1; --i)
		for (int j = m; j >= 1; --j)
			if (a[i][j] == '0')
			{
				rht[i][j] = rht[i][j + 1] + 1;
				rd[i][j] = (rht[i][j] - 1) * line[j];
				line[j]++;
			}  else rht[i][j] = rd[i][j] = line[j] = 0;
		
//		for (int i = 1; i <= n; ++i, cout << "\n")
//		for (int j = 1; j <= m; ++j)
//		  printf ("[%d, %d] : rht = %lld rd = %lld  |  ", i, j, rht[i][j], rd[i][j]);
		
		int resc = 0, resf = 0;
		for (int j = 1, sum, summ; j <= m; ++j)
		{
			sum = 0; summ = 0;
			for (int i = n - 2; i >= 1; --i)
			{
				if (a[i][j] == '1') continue;
				if (a[i + 2][j] == '1' || a[i + 1][j] == '1') 
				{
					sum = summ = 0;
				} else {
					sum += rht[i + 2][j] - 1;
					summ += rd[i + 2][j];
				}
				resc = add (resc, mul (rht[i][j] - 1, sum));
				resf = add (resf, mul (rht[i][j] - 1, summ));
//				printf ("[%d, %d] : sum = %lld summ = %lld | C add %lld * %lld = %lld | F add %lld * %lld = %lld\n", i, j, sum, summ, rht[i][j] - 1, sum, mul (rht[i][j] - 1, sum), rht[i][j] - 1, summ, mul (rht[i][j] - 1, summ));
			}
		}
		
		cout << mul (resc, c) << " " << mul (resf, f) << "\n";
	}
	
	return 0;
}
