#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Maxn=1050;
const int mod=998244353;
int T,n,m,c,f,i,j,k,p,anc,anf,jlc,jlf;
int a[Maxn][Maxn],h[Maxn][Maxn],s[Maxn][Maxn];
int read()
{
	int s=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		s=(s<<3)+(s<<1)+c-'0';
		c=getchar();
	}
	return s*f;
}
int readc()
{
	char c=getchar();
	while(c<'0'||c>'9')
	{
		c=getchar();
	}
	return c-'0';
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read(),read();
	while(T)
	{
		n=read(),m=read(),c=read(),f=read();
		anc=anf=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				a[i][j]=readc(),h[i][j]=s[i][j]=0;
			}
			h[i][m+1]=0;
		}
		for(i=1;i<=m;i++)
		{
			s[n+1][i]=0;
		}
		for(i=1;i<=n;i++)
		{
			for(j=m;j>=1;j--)
			{
				if(!a[i][j]) h[i][j]=h[i][j+1]+1;
			}
		}
		for(i=n;i>=1;i--)
		{
			for(j=1;j<=m;j++)
			{
				if(!a[i][j]) s[i][j]=s[i+1][j]+1;
			}
		}
		for(j=1;j<m;j++)
		{
			i=1;
			while(i<n)
			{
				if(s[i][j]<3)
				{
					i=i+s[i][j]+1;
					continue;
				}
				jlc=jlf=0;
				for(k=2;k<s[i][j];k++)
				{
					jlc=jlc+h[i+k][j]-1;
					jlf=jlf+(h[i+k][j]-1)*(s[i+k][j]-1);
				}
				anc=(anc+(h[i][j]-1)*jlc)%mod;
				anf=(anf+(h[i][j]-1)*jlf)%mod;
				for(k=1;k<s[i][j]-2;k++)
				{
					p=i+k;
					jlc=jlc+1-h[p+1][j];
					jlf=jlf-(h[p+1][j]-1)*(s[p+1][j]-1);
					if(h[p][j]>1)
					{
						anc=(anc+(h[p][j]-1)*jlc)%mod;
						anf=(anf+(h[p][j]-1)*jlf)%mod;
					}
				}
				i=i+s[i][j];
			}
		}
		printf("%lld %lld\n",anc*c,anf*f);
		T--;
	}
	return 0;
}