#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=998244353;
int T,id;
int n,m,c,f;
int cntup,cntdo,cntx;
ll summ,sumc,sumf;
int a[1010][1010];
char s[1010];
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);
		for(int i=1; i<=n; ++i)
		{
			for(int j=1;j<=m;++j)
			{
				cin>>s[i];
				if(s[i]=='1') a[i][j]=1;
				else a[i][j]=0;
			}
		}
		if(c==0 && f==0)
		{
			printf("0 0\n");
			continue;
		}
		for(int i=1; i<=n-2; ++i)
		{
			for(int j=1; j<=m-1; ++j)
			{
				
				if(a[i][j]==1 || a[i][j+1]==1 ||
				    a[i+1][j]==1 || a[i+2][j]==1) continue;
				for(int jc=3; jc<=n-i+1; ++jc)
				{
					cntup=0,cntdo=0,cntx=0;
					if(a[i+jc-1][j]==1) break;
					if(a[i+jc-1][j+1]==1) continue;
					for(int k=j+2; k<=m; ++k)
					{
						if(a[i][k]==0) cntup++;
						else break;
					}
					for(int k=j+2; k<=m; ++k)
					{
						if(a[i+jc-1][k]==0) cntdo++;
						else break;
					}
					for(int k=i+jc;k<=n;++k)
					{
						if(a[k][j]==1) break;
						else cntx++;
					}
					summ=(cntup+1)*(cntdo+1)%MOD;
					sumc=(sumc+summ)%MOD;
					sumf=(sumf+summ*cntx%MOD)%MOD;
				}
			}
		}
		printf("%lld %lld\n",c*sumc%MOD,f*sumf%MOD);
	}
	return 0;
}
