#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int t,id;
int n,m,cx,fx,sum1[1005][1005],sum2[1005][1005],f,sumc,sumf;
char a[1005][1005];
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0')
	{
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>t>>id;
	while(t--)
	{
		cin>>n>>m>>cx>>fx;
		sumc=0;sumf=0;
		if(cx==0&&fx==0)cout<<0<<" "<<0<<endl;
		else {
		for(int i=0;i<=1001;i++)
			for(int j=0;j<=1001;j++)
			{
				a[i][j]='1';
				sum1[i][j]=0;
				sum2[i][j]=0;
			}	
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>a[i][j];
		for(int i=1;i<=n;i++)
		{
			f=0;
			for(int j=m;j>=1;j--)
			{
				if(a[i][j]=='0')
				{
					if(f)sum1[i][j]=sum1[i][j+1]+1;
					f=1;
				}else f=0;
			}
		}
		for(int i=1;i<=m;i++)
		{
			f=0;
			for(int j=n;j>=1;j--)
			{
				if(a[j][i]=='0')
				{
					if(f)sum2[j][i]=sum2[j+1][i]+1;
					f=1;
				}else f=0;
			}
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				for(int k=i+2;k<=i+sum2[i][j];k++)
				{
					sumc=(sumc+sum1[i][j]*sum1[k][j])%mod;
					if(k<i+sum2[i][j])sumf=(sumf+sum1[i][j]*sum1[k][j]*(i+sum2[i][j]-k))%mod;
				}
			}
		cout<<sumc*cx%mod<<" "<<sumf*fx%mod<<endl;
		}
	}
	return 0;
}


		/*for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				cout<<sum1[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				cout<<sum2[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;*/
