#include<bits/stdc++.h>
#define N 1010
using namespace std;
typedef long long ll;
const ll mod=998244353;
inline ll rl(){
	ll ans=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')ans=ans*10+c-'0',c=getchar();
	return ans*f;
}
ll T,id,n,m,ans,ct,ft;
bool a[N][N];
ll c[N][N];
ll x,y,z,w;
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=rl(),id=rl();
	while(T--){
		n=rl(),m=rl(),ct=rl(),ft=rl();//read
		ll j;
		for(ll i=1;i<=n;i++){
			j=0;
			char c=getchar();
			while(c!='0'&&c!='1')c=getchar();
			while(c=='0'||c=='1')a[i][++j]=c-'0',c=getchar();
		}
		memset(c,0,sizeof(c));
		//work c
		for(ll i=n;i>=1;i--){
			for(ll j=m;j>=1;j--){
				if(a[i][j])c[i][j]=0;
				else c[i][j]=c[i][j+1]+1;
			}
		}
		for(ll j=m;j>=1;j--){
			y=z=0;
			for(ll i=n;i>=1;i--){
				if(a[i][j]){
					y=z=0;
					continue;
				}
				x=c[i][j]-1;
				ans=(ans+x*y%mod)%mod;
				y+=z;
				z=c[i][j]-1;
			}
		}
		printf("%lld ",ans*ct%mod);
		//work f
		ans=0;
		for(ll j=m;j>=1;j--){
			y=z=w=0;
			for(ll i=n;i>=1;i--){
				if(a[i][j]){
					y=z=w=0;
					continue;
				}
				x=c[i][j]-1;
				ans=(ans+x*y%mod)%mod;
				y=(y+z*(w-1)%mod)%mod;
				z=c[i][j]-1;
				w++;
			}
		}
		printf("%lld\n",ans*ft%mod);
		//AC
	}
	return 0;
}
