#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define PNAME "plant"

#ifdef LOCAL_TEST
#define FNAME PNAME "3"
#else
#define FNAME PNAME
#endif

const int max_n = 1000;

char mp[max_n][max_n + 1];
int rm[max_n][max_n], dn[max_n][max_n];

struct mod_int
{
	static const int mod = 998244353;
	int x;
	
	void _add(int &_x, int y) { _x += y; if (_x >= mod) _x -= mod; }
	void _mv(int &_x) { _add(_x, mod); }
	
	template<class T>
	mod_int(T y)
	{
		x = (static_cast<int>(y) % mod + mod) % mod;
	}
	// mod_int(const mod_int& m) : x(m.x) { }
	mod_int() : x(0) { }
	
	mod_int& operator+=(const mod_int md)
	{
		_add(x, md.x);
		return *this;
	}
	
	mod_int operator*=(const mod_int md)
	{
		x = 1ull * x * md.x % mod;
		return *this;
	}
	
	mod_int operator*(const mod_int md) const
	{
		mod_int ret = *this;
		ret *= md;
		return ret;
	}
	
	friend ostream& operator<<(ostream& os, const mod_int& m)
	{
		os << m.x;
		return os;
	}
};

signed main()
{
	freopen(FNAME ".in", "r", stdin);
	freopen(FNAME ".out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int cas, id, n, m, c, f;
	
	cin >> cas >> id;
	while (cas--)
	{
		memset(rm, 0, sizeof rm);
		memset(dn, 0, sizeof dn);
		
		cin >> n >> m >> c >> f;
		for (int i = 0; i < n; i++)
		{
			cin >> mp[i];
			for (int j = m - 1; j >= 0; j--)
				if (mp[i][j] == '0')
				{
					rm[i][j] = 1;
					if (j < m - 1)
						rm[i][j] += rm[i][j + 1];
				}
		}
		for (int j = 0; j < m; j++)
			for (int i = n - 1; i >= 0; i--)
				if (mp[i][j] == '0')
				{
					dn[i][j] = 1;
					if (i < n - 1)
						dn[i][j] += dn[i + 1][j];
				}
		
		// for (int i = 0; i < n; i++)
		// 	for (int j = 0; j < m; j++)
		// 		cerr << rm[i][j] << " \n"[j == m - 1];
		
		mod_int ansc = 0, ansf = 0, curl = 0;
		for (int j = 0; j < m; j++)
		{
			curl = 0;
			for (int i = 0; i < n; i++)
				if (mp[i][j] == '1')
					curl = 0;
				else
				{
					ansc += curl * (rm[i][j] - 1);
					ansf += curl * (rm[i][j] - 1) * (dn[i][j] - 1);
					if (i >= 1 && mp[i - 1][j] == '0' && rm[i - 1][j] > 0)
						curl += rm[i - 1][j] - 1;
					// cerr << ansc << " " << ansf << " " << i << " " << j << endl;
				}
		}
		
		cout << ansc * c << " " << ansf * f << "\n";
	}
	
	return 0;
}