#include<bits/stdc++.h>
using namespace std;
#define re register
const int mod = 998244353 , N = 1e3+10;
int n,c,m,f,a[N][N];
char s[N][N];
int checkc()
{
	int ans=0;
	for (re int i=1;i<n-1;i++)
	for (re int j=1;j<m;j++)
	{
		if (a[i][j]>1)
		for (re int k=i+1;k<=n;k++)
		{
			if (a[k][j]==0) break;
			if (a[k][j]==1) continue;
			if (a[k][j]>1&&k>i+1) ans+=(a[i][j]-1)*(a[k][j]-1);
		}
	}
	return ans;
}
int checkf()
{
	int ans=0;
	for (re int i=1;i<n-2;i++)
	for (re int j=1;j<m;j++)
	{
		if (a[i][j]>1)
		for (re int k=i+1;k<n;k++)
		{
			if (a[k][j]==0) break;
			if (a[k][j]==1) continue;
			if (a[k][j]>1&&k>i+1)
			{
				for (re int o=k+1;o<=n;o++)
				if (a[o][j]==0) break;
				else ans+=(a[i][j]-1)*(a[k][j]-1);
			}
		}
	}
	return ans;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(0);
	int T,id;
	cin >> T >> id;
	while (T--)
	{
		cin >> n >> m >> c >> f;
		for (re int i=1;i<=n;i++) cin >> s[i]+1;
		for (re int i=1;i<=n;i++) a[i][m+1]=0;
		for (re int i=1;i<=n;i++)
		{
			for (re int j=m;j>=1;j--)
			{
				if (s[i][j]=='0') a[i][j]=a[i][j+1]+1;
				else a[i][j]=0;
			}
		}
		int C=checkc();
		int F=checkf();
		cout << (c*C%mod) << " " << (f*F%mod) << endl;
	}
	return 0;
}