#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1005;
const int mod=998244353;
int t,id;
int n,m,c,f;
int sum[maxn][maxn],tmp[maxn];
char a[maxn][maxn];
void rd(int &rex)
{
	char c=getchar();int f=1;rex=0;
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c>='0'&&c<='9')rex=rex*10+c-'0',c=getchar();
	rex*=f;
}
int main()
{
	freopen("plant.in","r",stdin); freopen("plant.out","w",stdout);
	rd(t);rd(id);
	while(t--)
	{
		LL cans=0,fans=0;
		rd(n);rd(m);rd(c);rd(f);
		for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
		memset(sum,0,sizeof(sum));
		for(int i=1;i<=n;i++)
		for(int j=m;j;j--)sum[i][j]=a[i][j]=='1'?0:sum[i][j+1]+1;
//		for(int i=1;i<=n;i++,putchar('\n'))
//		for(int j=1;j<=m;j++)printf("%d",sum[i][j]);
		for(int j=1,l,r;j<=m;j++)
		for(int i=1;i<=n;)
		{
			l=i;
			while(l<=n&&a[l][j]=='1')l++;
			r=l;
			while(r<=n&&a[r][j]=='0')r++;
			tmp[r]=0;
			for(int k=r-1;k>=l;k--)tmp[k]=tmp[k+1]+sum[k][j]-1;
			for(int k=l;k<r-2;k++)cans+=1LL*(sum[k][j]-1)*tmp[k+2]%mod;
			for(int k=l;k<r-3;k++)fans+=1LL*(sum[k][j]-1)*(tmp[k+2]-tmp[r-1])*(r-l-3)%mod;
			cans%=mod,fans%=mod;
			i=r;
		}
		printf("%lld %lld\n",cans*c,fans*f);
	}
	return 0;
}/*1 0
4 3 1 1
001
010
000
000
*/