#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1005,md=998244353;
char s[N][N];
int f[N][N],p0[N],p1[N];
int n,m,_c,_f,T,id,ansc,ansf;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	for(cin>>T>>id;T--;){
		cin>>n>>m>>_c>>_f;
		for(int i=1;i<=n;++i)cin>>(s[i]+1);
		for(int i=1;i<=n;++i){
			int ct=0;
			for(int j=m;j;--j){
				if(s[i][j]=='1')ct=0;
				else++ct;
				f[i][j]=max(ct-1,0);
			}
		}
		ansc=ansf=0;
		for(int j=1;j<=m;++j){
			memset(p0,0,sizeof p0);
			memset(p1,0,sizeof p1);
			for(int i=1;i<=n;++i)if(s[i][j]=='0')
				p0[i]=(p0[i-1]+f[i][j])%md;
			for(int i=3;i<=n;++i)if(s[i][j]=='0'){
				int t=(LL)f[i][j]*p0[i-2]*(s[i-1][j]=='0')%md;
				ansc=(ansc+t)%md;
				p1[i]=(p1[i-1]+t)%md;
			}
			for(int i=2;i<=n;++i)if(s[i][j]=='0')
				ansf=(ansf+p1[i-1])%md;
		}
		ansc=(LL)ansc*_c%md;
		ansf=(LL)ansf*_f%md;
		cout<<ansc<<' '<<ansf<<'\n';
	}
	return 0;
}
