//goodbye,OI
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1010,mod=998244353;
int sum[N][N],n,m,c,f;char a[N][N];
void solve()
{
	scanf("%d%d%d%d",&n,&m,&c,&f);memset(sum,0,sizeof(sum));
	int ans1=0,ans2=0;
	for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=m;j>=1;j--)
		    if(a[i][j]=='0') sum[i][j]=sum[i][j+1]+1;
		    else sum[i][j]=0;
	}
	for(int j=1;j<=m;j++)
	{
		int st,tmp=0,res=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i][j]=='1') continue;
			if(i==1||a[i-1][j]=='1') {st=i;tmp=0;res=0;continue;}
			ans1=(ans1+1ll*tmp*(sum[i][j]-1)%mod)%mod;
			ans2=(ans2+res)%mod;
			res=(res+1ll*tmp*(sum[i][j]-1)%mod)%mod;
			tmp=(tmp+sum[i-1][j]-1)%mod;
		}
	}
	printf("%d %d\n",c*ans1%mod,f*ans2%mod);
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;scanf("%d%d",&T,&id);while(T--) solve();
	return 0;
}