#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int Mod=998244353;
//int read()
//{
//	int p=1,ans=0;
//	char ch;
//	for(ch=getchar();ch<'0'||ch>'9';ch=getchar())
//	if(ch=='-') p=-1;
//	ans=ch-'0';
//	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())
//	ans=(ans<<1)+(ans<<3)+ch-'0';
//	return ans*p;
//}
int T,id,n,m,c,f;
ll a[1500][1500],b[1500][1500],he[1500],ansc,ansf;
char s[1500][1500];
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d %d",&T,&id);
	while(T--)
	{
		memset(a,0,sizeof(a));
		sizeof(b,0,sizeof(b));
		ansc=ansf=0;
		scanf("%d %d %d %d",&n,&m,&c,&f);
		for(int i=1;i<=n;i++)
		{
			scanf("%s",s[i]);
			for(int j=m;j>=1;j--)
			{if(s[i][j-1]=='0') a[i][j]=a[i][j+1]+1;
			else a[i][j]=0;
			}
		}
		
		for(int j=1;j<=m;j++)
		for(int i=n;i>=1;i--)
		{if(s[i][j-1]=='0') b[i][j]=b[i+1][j]+1;
		else b[i][j]=0;
		}
		for(int j=1;j<=m;j++)
		{
			memset(he,0,sizeof(he));
			int p=0;
			for(int i=1;i<=n;i++)
			{
				if(s[i][j-1]=='0') p++,he[i]=(he[i-1]+a[i][j]-1)%Mod;
				else p=0,he[i]=0;
				if(p>=3) ansc=(ansc+he[i-2]*(a[i][j]-1)%Mod)%Mod,ansf=(ansf+he[i-2]*(a[i][j]-1)%Mod*(b[i][j]-1)%Mod)%Mod;
				//cout<<ansf<<endl;
			}
		}
		printf("%lld %lld\n",ansc*c%Mod,ansf*f%Mod);
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}