#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int n,m,c,a[1010][1010],f,s[1010],A[1010][1010],C[1010][1010];
char ch;
inline void solve(){
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	A[i][j]=C[i][j]=0;
	cin>>n>>m>>c>>f;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	cin>>ch,a[i][j]=ch-'0';
	for(int i=1;i<=n;i++)for(int j=m;j;j--)
	if(a[i][j]==1)A[i][j]=0;
	else A[i][j]=A[i][j+1]+1;
	int resC=0,resF=0;
	for(int j=1;j<=m;j++){
		for(int i=0;i<=n;i++)s[i]=0;
		int p=0;
		for(int i=1;i<=n;i++){
			if(!a[i][j]){
				s[i]=s[i-1]+A[i][j]-1;
				if(i-2>p){
					C[i][j]=(C[i-1][j]+(A[i][j]-1)*s[i-2]%mod)%mod;
					resC=(resC+(A[i][j]-1)*s[i-2]%mod)%mod;
					if(i-3>p)resF=(resF+C[i-1][j])%mod;
				}
			}
		    else p=i;
		}
	}
	resC=resC*c%mod,resF=resF*f%mod;
	cout<<resC<<' '<<resF<<'\n';
}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	std::ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T,ID;cin>>T>>ID;
	while(T--)solve();
	return 0;
}