#include<iostream>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
const int N=1e3+5,P=998244353;
int T,n,m,c,f,id,row[N][N],col[N][N],g[N][N];
char s[N];
int read(int& v)
{
	char ch; int f=1;
	for(ch='*';!isdigit(ch) && ch!='-';ch=getchar());
	if(ch=='-')  f=-1,ch=getchar();
	for(v=0;isdigit(ch);v=v*10+ch-'0',ch=getchar());
	v*=f;
return v;
}
void solve()
{
	read(n),read(m),read(c),read(f);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)  g[i][j]=s[j]-'0';	
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(g[i][j]){ row[i][j]=col[i][j]=0; continue; }
			int cnt_row=1,cnt_col=1,pos;
			pos=i+1; while(pos<=n && !g[pos][j])  cnt_row++,pos++;
			pos=j+1; while(pos<=m && !g[i][pos])  cnt_col++,pos++;
			row[i][j]=cnt_row,col[i][j]=cnt_col;
		}
	int ansC=0,ansF=0;
	for(int y0=1;y0<=m;y0++)
		for(int x1=1;x1<=n;x1++)
			for(int x2=x1+2;x2<=n;x2++)
			{
				if(row[x1][y0]<x2-x1+1 || g[x1][y0])  continue;
				int rec=(col[x1][y0]-1)*(col[x2][y0]-1)%P;
				ansC=(ansC+rec)%P;
				ansF=(ansF+rec*(row[x2][y0]-1)%P);
			}
	printf("%lld %lld\n",ansC*c,ansF*f);
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	read(T),read(id);
	while(T--)  solve();
return 0;
}