#include<bits/stdc++.h>
//ti du cuo le  40min
#define int long long
using namespace std;
const int mod=998244353;
int mp[1005][1005],g[1005][1005];
int T,n,id,m,c,f;
signed main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld%lld",&T,&id);
	while(T--) {
		scanf("%lld%lld%lld%lld",&n,&m,&c,&f);
		memset(mp,0,sizeof(mp));
		memset(g,0,sizeof(g));
		int cntc=0,cntf=0; 
		for(int i=1; i<=n; ++i) {
			for(int j=1; j<=m; ++j) {
				scanf("%1lld",&mp[i][j]);
				mp[i][j]^=1;
				g[i][j]=mp[i][j];
			}
		}
		for(int i=1; i<=n; ++i) {
			for(int j=m; j; --j) {
				if(mp[i][j]) mp[i][j]=mp[i][j+1]+1;
			}
		}
		for(int j=1;j<=m;++j){
			for(int i=n;i;--i){
				if(g[i][j]) g[i][j]+=g[i+1][j];
			}
		}
//		for(int i=1; i<=n; ++i) {
//			for(int j=1; j<=m; ++j) printf("%lld",g[i][j]);
//			puts("");
//		}
//		puts("!!!");
		for(int j=1; j<m; ++j) {
			int before=0;
			for(int i=2; i<=n; ++i) {
				if(mp[i][j]>0) {
					if(mp[i-1][j]>0&&mp[i-2][j])before=(before+mp[i-2][j+1])%mod;
					else before=0;
					cntc=(cntc+mp[i][j+1]*before%mod)%mod;
					cntf=(cntf+mp[i][j+1]*before%mod*g[i+1][j])%mod;
				} else before=0;
//				printf("%lld ",before);
			}
//			puts("");
		}
		printf("%lld %lld\n",cntc*c%mod,cntf*f%mod);
        
	}

	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/