#include<bits/stdc++.h>
template<typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f=0;while(!isdigit(ch))f|=ch=='-',ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
const int N=1005,mod=998244353;typedef long long ll;
char s[N][N];int len[N];ll s0[N],s1[N];
void MAIN(){
	int n,m,c,f;read(n),read(m),read(c),read(f);
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	ll C=0,F=0;
	for(int j=m;j>=1;--j){
		for(int i=1;i<=n;++i)len[i]=s[i][j]=='0'?len[i]+1:0;
		for(int i=1;i<=n;++i)s0[i]=s0[i-1]+len[i]-1;
		for(int i=1;i<=n;++i)s1[i]=s1[i-1]+1LL*i*(len[i]-1);
		int las=n;
		for(int i=n;i>=1;--i){
			if(s[i][j]=='1')las=i-1;
			else{
				if(i+2<=las){
					C+=1LL*(len[i]-1)*(s0[las]-s0[i+1]);
					F+=1LL*las*(len[i]-1)*(s0[las]-s0[i+1])-1LL*(len[i]-1)*(s1[las]-s1[i+1]);
				}
			}
		}
	}
	printf("%lld %lld\n",(c*C)%mod,(f*F)%mod);
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int _,id;read(_),read(id);
	while(_--)MAIN();
	return 0;
}
