#include<bits/stdc++.h>
using namespace std;

const int N=1001;
const int Mod=998244353;
int n,m,a[N][N],c,f,dn[N][N],r[N][N],T,id;
long long ansc,ansf;

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);
		memset(a,0,sizeof(a));
		memset(dn,0,sizeof(dn));
		memset(r,0,sizeof(r));
		ansc=0,ansf=0;
		string s;
		for(int i=1;i<=n;i++)
		{
			cin>>s;
			for(int j=0;j<m;j++)
			{
				if(s[j]=='1') 
					a[i][j+1]=1;
				else
					a[i][j+1]=0;
			}	
		}		
		if(c==0 and f==0)
		{
			printf("0 0\n");
			return 0;
		}
		for(int i=n-1;i>=1;i--)
			for(int j=1;j<=m;j++)
			{
				if(a[i][j]==1)
					continue;
				if(a[i+1][j]==0)
					dn[i][j]=dn[i+1][j]+1;
			}	
		for(int i=1;i<=n;i++)
			for(int j=m-1;j>=1;j--)
			{
				if(a[i][j]==1)
					continue;
				if(a[i][j+1]==0)
					r[i][j]=r[i][j+1]+1;
			}	
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(dn[i][j]>=2)
				{
					long long cnt=r[i][j];
					for(int k=i+2;k<=i+dn[i][j];k++)
					{
						if(r[k][j]>=1)
						{
							ansc=(ansc+cnt*r[k][j]%Mod)%Mod;
							ansf=(ansf+cnt*r[k][j]*dn[k][j]%Mod)%Mod;
						}
					}
				}
			}
		}
		printf("%lld %lld\n",ansc*c,ansf*f);
	}
	return 0;
}