#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
const int mod=998244353;
int n,m,t,id,f,c;
char Map[1005][1005];
long long cnt[1005][1005],ans;
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++)
			for (int j=1;j<=m;j++)
				scanf(" %c",&Map[i][j]);
		for (int i=1;i<=n;i++)
			cnt[i][m+1]=0;
		for (int i=1;i<=n;i++)
		{
			for (int j=m;j>=1;j--)
			{
				if (Map[i][j]=='1')
					cnt[i][j]=0;
				else
					cnt[i][j]=cnt[i][j+1]+1;
			}	
		}
		/*for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=m;j++)
				printf("%lld ",cnt[i][j]);
			printf("\n");
		}	*/
		ans=0;
		for (int j=1;j<=m;j++)
		{
			long long sum[1005];
			sum[n+1]=0;
			for (int i=n;i>=1;i--)
			{
				if (i<=n-2 && cnt[i][j]>1)
					ans=(1LL*(cnt[i][j]-1)*(sum[i+2])%mod+ans)%mod;
				if (Map[i][j]=='1')
				{
					sum[i]=0;
					sum[i+1]=0;
				}
				else
					sum[i]=(sum[i+1]+cnt[i][j]-1)%mod;
			}
		}
		printf("%lld ",ans*c);
		ans=0;
		for (int j=1;j<=m;j++)
		{
			long long sum[1005],lst=0;
			sum[n+1]=0;
			for (int i=n;i>=1;i--)
			{
				if (i<=n-2 && cnt[i][j]>1)
					ans=(1LL*(cnt[i][j]-1)*sum[i+2]%mod+ans)%mod;
				if (Map[i][j]=='1')
				{
					sum[i]=0;
					sum[i+1]=0;
					lst=0;
				}
				else
				{
					sum[i]=(sum[i+1]+(cnt[i][j]-1)*lst)%mod;
					lst++;
				}
			}
		}
		printf("%lld\n",ans*f);
	}
	return 0;
}