#include<bits/stdc++.h>
#define fori(i,a,b) for(i=a;i<=b;i++)
#define ford(i,a,b) for(i=a;i>=b;i--)
typedef long long ll;
typedef double db;
using namespace std;
const int Mod=998244353;
const int N=2003;
ll n,m,cc,ff,id,T,i,j,f1[N][N],fsum[N][N],f2[N][N];
char a[N][N],ch;
void solve()
{
	ll i,j,num,bo,ansc,ansf;
	ansc=0; ansf=0;
	fori(i,1,n)
	{
		num=0;
		ford(j,m,1)
		if (a[i][j]=='1')
		{
			num=0;
			f1[i][j]=0;
		} else {
			num++;
			f1[i][j]=num-1;
		}
	}
	fori(i,1,m)
	{
		fori(j,1,n)
		fsum[j][i]=fsum[j-1][i]+f1[j][i];
		num=0;
		ford(j,n,1)
		if (a[j][i]=='1')
		{
			num=0;
			f2[j][i]=0;
		} else {
			num++;
			f2[j][i]=num-1;
		}
	}
	fori(i,1,m)
	{
		bo=0;
		fori(j,1,n)
		if (a[j][i]=='1') 
		{
			bo=0;
		} else {
			if (bo==0) bo=j;
			else {
				if (bo<j-1)
				{
					ansc+=f1[j][i]*(fsum[j-2][i]-fsum[bo-1][i])%Mod;
			    	ansc%=Mod;
			    	ansf+=f1[j][i]*(fsum[j-2][i]-fsum[bo-1][i])%Mod*f2[j][i]%Mod;
				}
			}
		}	
	}
	printf("%lld %lld\n",ansc*cc%Mod,ansf*ff%Mod);
}
int main()
{
	freopen("plant.in","r",stdin); freopen("plant.out","w",stdout);
	scanf("%lld%lld",&T,&id);
	while (T--)
	{
		scanf("%lld%lld%lld%lld",&n,&m,&cc,&ff);
		fori(i,1,n)
		 fori(j,1,m)
		 {
		 	scanf("%c",&ch);
		 	while (ch!='0'&&ch!='1') scanf("%c",&ch);
		 	a[i][j]=ch;
		 }
		solve();
	}
}