#include <bits/stdc++.h>
#define FOR(x,l,r) for(int x = l; x <= r; ++x)
#define _FOR(x,l,r) for(int x = r; x >= l; --x)
using namespace std;
const int MOD = 998244353, N = 1005;
int n, m, cc, f, a[N][N], b[N][N], c[N][N], T, id;
inline long long cal(int l, int r, int c)
{
	return 1ll * (b[l][c] - 1) * (b[r][c] - 1);
}
int main()
{
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin >> T >> id;
	while (T--)
	{
		cin >> n >> m >> cc >> f;
		memset (b, 0, sizeof(b));
		memset (c, 0, sizeof(c));
		if (c == 0 && f == 0)
		{
			puts("0");
			continue;
		}
		FOR(i, 1, n)
		{
			string s;
			cin >> s;
			_FOR(j, 1, m)
			{
				a[i][j] = s[j - 1] == '0';
				b[i][j] = a[i][j] + b[i][j + 1];
				c[i][j] = a[i][j] + c[i - 1][j];
				if (s[j - 1] == '1') b[i][j] = 0;
				if (s[j - 1] == '1') c[i][j] = 0;
			}
		}
		long long ansc = 0, ansf = 0;
		FOR(i, 1, m)
		{
			FOR(j, 1, n)
			{
				if (c[j][i] >= 3)
				{
					FOR(k, j - c[j][i] + 1, j - 2)
					{
						int sum = cal(k,j,i);
						ansc += sum;
						ansc %= MOD;
						int tmp = j + 1;
						while (c[tmp][i] != c[tmp - 1][i] && c[tmp][i])
						{
							ansf += sum;
							ansf %= MOD;
							tmp++;
						}
					}
				}
			}
		} 
		cout << ansc * cc % MOD << " " << ansf * f % MOD << endl;
	}
	return 0;
}