#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+10;
const int mod=998244353;
int T,id;
int n,m,c,f;
int Vc,Vf;
int up[N],down[N],r[N][N];
char a[N][N];
void solve()
{
	Vc=Vf=0;
	memset(r,0,sizeof r);
	cin>>n>>m>>c>>f;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]+1;
		for(int j=m;j>=1;j--)
		{
			if(a[i][j]=='1') continue;
			r[i][j]=max(r[i][j+1],j);
		}
	}
	for(int j=1;j<=m;j++)
	{
		memset(up,0,sizeof up);
		memset(down,0,sizeof down);
		for(int i=n;i>=1;i--)
			down[i]=(a[i][j]=='1'? 0:down[i+1]+1);
		for(int i=1;i<=n;i++)
		{
			if(a[i][j]=='1')
			{
				up[i]=up[i+1]=0;
				continue;
			}
			up[i]+=up[i-1];
			int len=r[i][j]-j;
			Vc=(Vc+len*up[i]%mod)%mod;
			Vf=(Vf+len*up[i]%mod*(down[i]-1)%mod)%mod;
			up[i+2]+=len;
//			cout<<"d="<<down[i]<<" len="<<len<<" Vc="<<Vc<<" Vf="<<Vf<<'\n';
		}
	}
	cout<<Vc*c%mod<<' '<<Vf*f%mod<<endl;
}
signed main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>T>>id;
	while(T--) solve();
}