#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+7;
const ll mod=998244353;
int read()
{
	int res=0,f=1;
	char c=getchar();
	while(c!='-' && !isdigit(c)) c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(isdigit(c)) res=res*10+c-48,c=getchar();
	return res*f;
}
int readc()
{
	char c=getchar();
	while(c!='0' && c!='1') c=getchar();
	return (c=='1');
}
int n,m;
ll C,F;
int a[1010][1010];
ll f[1010][1010],g[1010][1010],sum[1010][1010];
ll ans1,ans2;
void init()
{
	for(int i=0;i<=n+1;i++)
		for(int j=0;j<=m+1;j++)
			f[i][j]=g[i][j]=sum[i][j]=0;
	ans1=ans2=0;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T=read(),id=read();
	while(T--)
	{
		n=read(),m=read(),C=read(),F=read();
		init();
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				a[i][j]=readc();
		for(int i=1;i<=n;i++)
		{
			g[i][m]=0;
			for(int j=m-1;j;j--)
			{
				g[i][j]=g[i][j+1]+1;
				if(a[i][j] || a[i][j+1]) g[i][j]=0;
			}
		}
		for(int j=1;j<=m;j++)
		{
			f[n][j]=0;
			for(int i=n-1;i;i--)
			{
				f[i][j]=f[i+1][j]+1;
				if(a[i][j] || a[i+1][j]) f[i][j]=0;
			}
		}
//		for(int i=1;i<=n;i++)
//		{
//			for(int j=1;j<=m;j++)
//				printf("%lld/%lld ",f[i][j],g[i][j]);
//			puts("");
//		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				(ans1+=sum[i-1][j]*g[i][j]%mod)%=mod;
				(ans2+=sum[i-1][j]*g[i][j]%mod*f[i][j]%mod)%=mod;
				if(a[i][j])
					sum[i][j]=0;
				else 
					sum[i][j]=(sum[i-1][j]+g[i-1][j])%mod;
			}
		}
		printf("%lld %lld\n",(ans1*C)%mod,(ans2*F)%mod);
	}
	return 0;
}