//I love Collei Forever!
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int n,m,c,f,ans1,ans2;
char a[2010][2010];
int r[2010][2010];
void solve(int p,int x,int y)
{
	int sum=0;
	for(int i=x;i<=y;i++)
	{
		ans1=(ans1+(r[i][p]-1)*sum)%mod;
		ans2=(ans2+(r[i][p]-1)*sum%mod*(y-i))%mod;
		sum=(sum+r[i][p]-1)%mod;
	}
	for(int i=x+1;i<=y;i++)
		ans1=(ans1-(r[i][p]-1)*(r[i-1][p]-1)%mod+mod)%mod,ans2=(ans2-(r[i][p]-1)*(r[i-1][p]-1)%mod*(y-i)%mod+mod)%mod;
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%lld%lld",&T,&id);
	while(T--)
	{
		memset(a,0,sizeof(a));
		memset(r,0,sizeof(r));
		scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
		for(int i=1;i<=n;i++)
			scanf("%s",a[i]+1);
		for(int i=1;i<=n;i++)
		{
			r[i][m+1]=0;
			for(int j=m;j>=1;j--)
				r[i][j]=(a[i][j]=='0'?r[i][j+1]+1:0);
		}
		ans1=0,ans2=0;
		for(int i=1;i<=m;i++)
		{
			int lst=1;
			for(int j=1;j<=n;j++)
			{
				if(a[j][i]=='1')
				{
					if(j-lst>=2)
						solve(i,lst,j-1);
					lst=j+1;
				}
			}
			if(n-lst+1>=2)
				solve(i,lst,n);
		}
		printf("%lld %lld\n",c*ans1%mod,f*ans2%mod);
	}
}
//Beaten by sunzh
