// Author:A weak man named EricQian
// Attention:Check your code while coding
// 100 pts
#include<bits/stdc++.h>
using namespace std;
#define infll 0x3f3f3f3f3f3f3f3fll
#define inf 0x3f3f3f3f
#define pb push_back
#define eb emplace_back
#define pa pair<int,int>
#define fi first
#define se second
#define all(x) ((x).bgein(),(x).end())
typedef long long ll;
#define Maxn 1005
#define mod 998244353
inline int rd()
{
	int x=0;
	char ch,t=0;
	while(!isdigit(ch = getchar())) t|=ch=='-';
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return t?-x:x;
}
int T,id,n,m,c,f,ansc,ansf;
int dp[Maxn][Maxn][4];
int Right[Maxn][Maxn];
char s[Maxn][Maxn];
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=rd(),id=rd();
	while(T--)
	{
		n=rd(),m=rd(),c=rd(),f=rd();
		memset(Right,0,sizeof(Right));
		memset(dp,0,sizeof(dp));
		ansc=ansf=0;
		for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
		for(int i=1,rmost;i<=n;i++)
		{
			rmost=-1;
			for(int j=m;j>=1;j--)
				if(s[i][j]=='1') rmost=-1;
				else
				{
					if(rmost==-1) rmost=j;
					else Right[i][j]=rmost-j;
				}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++) if(s[i][j]=='0')
			{
				dp[i][j][0]=Right[i][j];
				dp[i][j][1]=(dp[i-1][j][0]+dp[i-1][j][1])%mod;
				dp[i][j][2]=1ll*dp[i-1][j][1]*Right[i][j]%mod;
				dp[i][j][3]=(dp[i-1][j][2]+dp[i-1][j][3])%mod;
				ansc=(ansc+dp[i][j][2])%mod;
				ansf=(ansf+dp[i][j][3])%mod;
			}
		}
		printf("%d %d\n",(c*ansc)%mod,(f*ansf)%mod);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
