#include <cstdio>
#include <iostream>
#include <cstring>

const int Maxn=1e3+7;
const int Mod=998244353;

int nxtr[Maxn][Maxn];
char g[Maxn][Maxn];
int q[Maxn],cnt;
long long C,F,resc,resf;
int n,m,T;

int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%*d",&T);
	
	while(T--)
	{
		memset(nxtr,0,sizeof(nxtr));
		memset(g,0,sizeof(g));
		resc=resf=0;
		scanf("%d%d%lld%lld",&n,&m,&C,&F);
		
		for(int i=1;i<=n;++i)
			scanf("%s",g[i]+1);
			
		for(int i=1;i<=n;++i)
		{
			int lst=m+1;
			
			for(int j=m;j>=1;--j)
			{
				if(g[i][j]=='1')
					lst=j;
				else
					nxtr[i][j]=lst;	
			}
		}
		
	/*	for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				printf("%d%c",nxtr[i][j],j==m?'\n':' ');*/
		
		for(int j=1;j<=m;++j)
		{
			cnt=0;
			q[++cnt]=0;
			
			for(int i=1;i<=n;++i)
				if(g[i][j]=='1')
					q[++cnt]=i;
			
			q[++cnt]=n+1;
			
			/*for(int p=1;p<=cnt;++p)
				printf("%d ",q[p]);
			puts("");*/
			
			for(int p=1;p<=cnt-1;++p)
			{
				int l=q[p]+1,r=q[p+1]-1;
				
				for(int s=l;s<=r;++s)
					for(int t=s+2;t<=r;++t)
					{
						int lst1=nxtr[s][j],lst2=nxtr[t][j];
					//	printf("%d %d %d\n%d %d %d\n",j,lst1,lst2,s,t,r);
						if(lst1-j-1<=0||lst2-j-1<=0)
							continue;
						resc=(resc+1LL*(lst1-j-1)*(lst2-j-1)%Mod)%Mod;
					//	printf("%d %d %d\n",s,t,j);
						if(r-t<=0)
							continue;
						resf=(resf+1LL*(lst1-j-1)*(lst2-j-1)%Mod*(r-t)%Mod);
					}
			}
		}
		
		printf("%lld %lld\n",resc*C%Mod,resf*F%Mod);
	}
}