#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const ll mod = 998244353;
bool ar[1005][1005];
int right[1005][1005], down[1005][1005];
ll sum[1005][1005];
char s0[1005];
int main()
{
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	int t, id, n, m, c, f;
	ll cnt1, cnt2;
	scanf("%d%d", &t, &id);
	while(t--)
	{
		memset(ar, 0, sizeof ar);
		memset(right, 0, sizeof right);
		memset(down, 0, sizeof down);
		memset(sum, 0, sizeof sum);
		scanf("%d%d%d%d", &n, &m, &c, &f);
		for(int i = 1; i <= n; i++)
		{
			scanf("%s", s0 + 1);
			for(int j = 1; j <= m; j++)
				ar[i][j] = (s0[j] == '0');
		}
		for(int i = 1; i <= n; i++)
			for(int j = m; j; j--)
				if(ar[i][j]) right[i][j] = right[i][j + 1] + 1;
				else right[i][j] = 0;
		for(int j = 1; j <= m; j++)
			for(int i = n; i; i--)
				if(ar[i][j]) down[i][j] = down[i + 1][j] + 1;
				else down[i][j] = 0;
		cnt1 = cnt2 = 0;
		for(int j = 1; j <= m; j++)
			for(int i = 1; i <= n; i++)
			{
				if(!ar[i][j])
				{
					sum[i][j] = 0;
					continue;
				}
				sum[i][j] = sum[i - 1][j] + right[i][j] - 1;
				if(i > 2 && ar[i - 1][j])
				{
					cnt1 = (cnt1 + (ll)(right[i][j] - 1) * sum[i - 2][j]) % mod;
					cnt2 = (cnt2 + (ll)(right[i][j] - 1) * sum[i - 2][j] % mod * (down[i][j] - 1)) % mod;
				}
			}
		printf("%lld %lld\n", cnt1 * c % mod, cnt2 * f % mod);
	}
	return 0;
}
