#include<bits/stdc++.h>
#define LL long long
using namespace std;
int t,n,m,c,f,id;
int mod=998244353;
char a[1010][1010];
int w[1010][1010];
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>t>>id;
	while(t--)
	{
		memset(w,0,sizeof w);
		scanf("%d%d%d%d",&n,&m,&c,&f);
		if(c==0&&f==0){
			puts("0 0");
			continue;
		}
		for(int i=1;i<=n;i++)
		{
				scanf("%s",a[i]);
		}
		for(int i=1;i<=n;i++)
		{
			int cnt=0;
			for(int j=m-1;j>=0;j--)
			{
				if(a[i][j]=='1'){
					cnt=0;
				}
				else cnt++,w[i][j]=cnt;
			}
		}
		LL ans1=0,ans2=0;
		for(int j=0;j<m;j++)
		{
			int s=0;
			int cnt=0;
			int fl=0;
			LL res1=0,res2=0;
			for(int i=1;i<=n;i++)
			{
				if(a[i][j]=='0')
				{
					res2=(res2+res1)%mod;
					if(w[i][j]>1)fl=1;
					if(fl)cnt++;
					if(cnt>=3){
						res1=(res1+(LL)((s-w[i-1][j]+1+mod)%mod)*((w[i][j]-1+mod)%mod)%mod)%mod;
					}
					s+=(w[i][j]-1);
				}
				else s=0,cnt=0,fl=0,ans1=(res1+ans1)%mod,ans2=(res2+ans2)%mod,res1=0,res2=0;
			}
			ans1=(res1+ans1)%mod,ans2=(res2+ans2)%mod;
		}
		printf("%lld %lld\n",ans1*c%mod,ans2*f%mod);
	}
	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/