#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int M=1e3+5;
const ll mod=998244353;

int T,id,n,m;
ll ansc,ansf,c,f;
ll fx[M][M],fy[M][M];
char s[M][M];

int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	
	scanf("%d %d",&T,&id);
	while(T--)
	{
		memset(fx,0,sizeof(fx));
		memset(fy,0,sizeof(fy));
		ansf=ansc=0;
		
		scanf("%d %d %lld %lld",&n,&m,&c,&f);
		for(int i=1;i<=n;i++)
			scanf("%s",s[i]+1);
		
		for(int i=1;i<=n;i++)
			for(int j=m;j>=1;j--)
			{
				if(s[i][j]=='0')fx[i][j]=fx[i][j+1]+1ll;
				else fx[i][j]=0;
			}
		for(int i=1;i<=m;i++)
			for(int j=n;j>=1;j--)
			{
				if(s[j][i]=='0')fy[j][i]=fy[j+1][i]+1ll;
				else fy[j][i]=0;
			}
		
//		for(int i=1;i<=n;i++,cout<<endl)
//			for(int j=1;j<=m;j++)
//				printf("%d",fy[i][j]);
		
		
		for(int j=1;j<=m;j++)
		{
			int cnt=0;
			ll sum=0;
			for(int i=1;i<=n;i++)
			{
				if(s[i][j]=='0')
				{
					cnt++;
					if(cnt>=3)
					{
						ansc=(ansc+(fx[i][j]-1)*sum%mod)%mod;
						ansf=(ansf+(fx[i][j]-1)*sum%mod*fy[i+1][j])%mod;
						
					}
						
					if(i>1&&s[i-1][j]=='0')sum=(sum+fx[i-1][j]-1)%mod;
				}
				else cnt=sum=0;
//				printf("%d %d %d %d %d\n",i,j,ansc,ansf,sum);
			}
		}
		
		printf("%lld %lld\n",(ansc*c)%mod,(ansf*f)%mod);
	}
	
}//jian cha shu ru long long 
/*
2 0
4 3 1 1
001
010
000
000
6 6 1 1
000010
011000
000110
010000
011000
000000

*/