#include<cstdio>
const int N = 1010;
const long long Mod = 998244353;
int T,id,n,m,c,f;
char s[N][N],cntr[N][N],cntd[N][N],cntd1[N][N],cntd2[N][N];
long long ansc,ansf;
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while (T--)
	{
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for (int i = 1;i <= n;++i)
		{
			scanf("%s",s[i]+1),cntr[i][m+1] = 0;
			for (int j = m;j;--j)
				cntr[i][j] = (s[i][j] == '0')?(cntr[i][j+1]+1):0;
		}
		for (int j = 1;j < m;++j)
		{
			cntd[n+1][j] = cntd1[n+1][j] = cntd2[n+1][j] = 0;
			for (int i = n;i;--i)
				if (s[i][j] == '0')
					cntd[i][j] = cntd[i+1][j]+1,
					cntd1[i][j] = cntd1[i+1][j]+cntr[i][j]-1,
					cntd2[i][j] = cntd2[i+1][j]+1ll*(cntr[i][j]-1)*(cntd[i][j]-1);
				else
					cntd[i][j] = cntd1[i][j] = cntd2[i][j] = 0;
		}
		for (int i = 1;i <= n-2;++i)
			for (int j = 1;j < m;++j)
				if (cntd[i][j] > 2)
					ansc = (ansc+1ll*cntd1[i+2][j]*(cntr[i][j]-1))%Mod,
					ansf = (ansf+1ll*cntd2[i+2][j]*(cntr[i][j]-1))%Mod;
		printf("%d %d\n",ansc*c,ansf*f);
	}
	return 0;
}
