#include<bits/stdc++.h>

#define rd(x) x=read()

#define N 1005

using namespace std;

int T,id;
int n,m,c,f;
int a[N][N],l[N][N],s[N][N],d[N][N];
const int mod=998244353;

inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}

inline int upd(int x,int y){return (x+y)%mod;}

int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	rd(T),rd(id);
	while(T--)
	{
		rd(n),rd(m),rd(c),rd(f);int ans1=0,ans2=0;
		memset(a,0,sizeof(a)),memset(l,0,sizeof(l));
		memset(d,0,sizeof(d)),memset(s,0,sizeof(s));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				scanf("%1d",&a[i][j]);
		for(int i=n;i>=1;i--)
			for(int j=1;j<=m;j++)
				if(!a[i][j])
					d[i][j]=d[i+1][j]+1;
		for(int i=1;i<=n;i++)
		{
			for(int j=m;j>=1;j--)
				if(a[i][j]==0)
					l[i][j]=l[i][j+1]+1;
			for(int j=1;j<=m;j++)
				if(a[i][j]==0)
					s[i][j]=s[i-1][j]+l[i][j]-1;
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(a[i][j]==0)
					if(a[i-1][j]==0)
					{
						int x=1ll*s[i-2][j]*(l[i][j]-1)%mod;
						ans1=upd(ans1,x);
						ans2=upd(ans2,1ll*x*d[i+1][j]%mod);
					}
		printf("%d %d\n",1ll*ans1*c%mod,1ll*ans2*f%mod);
	}
	
	
	return 0;
}