#include<bits/stdc++.h>
using namespace std;
const int N=1010,md=998244353;

int n,m,C,F;
char ch[N];
bool bo[N][N];
int a[N][N],b[N][N],c,f,s;

inline void add(int &a,int b)
{
	a+=b;
	if (a>=md)a-=md;
}

int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%d%d",&T,&id);
	while (T--)
	{
		c=f=0;
		scanf("%d%d%d%d",&n,&m,&C,&F);
		for (int i=1;i<=n;i++)
		{
			scanf("%s",ch+1);
			for (int j=1;j<=m;j++)
			{
				if (ch[j]=='1')
				{
					bo[i][j]=1;
				}
				else bo[i][j]=0;
				a[i][j]=b[i][j]=0;
			}
		}
		for (int i=1;i<=n;i++)
		{
			a[i][m+1]=-1;
			for (int j=m;j>=1;j--)
			{
				if (bo[i][j]) a[i][j]=-1;
				else a[i][j]=a[i][j+1]+1;
			}
		}
		for (int j=1;j<=m;j++)
		{
			b[n+1][j]=-1;
			for (int i=n;i>=1;i--)
			{
				if (bo[i][j]) b[i][j]=-1;
				else b[i][j]=b[i+1][j]+1;
			}
		}
		for (int j=1;j<=m;j++)
		{
			s=0;
			for (int i=1;i<=n;i++)
			{
				if (bo[i][j]||bo[i-1][j])
				{
					s=0;
					continue;
				}
				add(c,1ll*a[i][j]*s%md);
				add(f,1ll*a[i][j]*s%md*b[i][j]%md);
				add(s,a[i-1][j]);
			}
		}
		printf("%lld %lld\n",1ll*c*C%md,1ll*f*F%md);
	
	}
		return 0;
}