#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1005;
const int dd=998244353;
int n,m,vc,vf;
int a[maxn][maxn],nxt[maxn][maxn];
inline int read(){
	char ch=getchar(); int ret=0,f=1;
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
inline int calc1(int x){return x*(x-1)/2;}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t=read(); int id=read();
	while(t--){
		n=read(); m=read(); vc=read(); vf=read();
		for(int k=1;k<=n;k++){
			char ch=getchar();
			int j=0;
			while(!isdigit(ch)) ch=getchar();
			while(isdigit(ch))a[k][++j]=1-(ch-'0'),ch=getchar();
		}
		for(int k=1;k<=n;k++)
		for(int j=m;j>=1;j--)
		if(a[k][j]) nxt[k][j]=nxt[k][j+1]+1;
		int ans1=0,ans2=0,cnt=0;
		for(int k=1;k<=m;k++){
			int pre=0,now=0;
			for(int j=1;j<=n+1;j++){
				if(!a[j][k]){
					now=0;
					cnt=0;
					continue;
				}
				ans1+=(nxt[j][k]-1)*now;
				ans2+=cnt;
				cnt+=(nxt[j][k]-1)*now;
				now+=max(nxt[j-1][k]-1,0ll);
//				cout<<"cnt="<<cnt<<endl;
//				cout<<"check "<<j<<" "<<k<<" "<<now<<" "<<ans1<<" "<<ans2<<" "<<nxt[j][k]<<endl;
			}
			ans1%=dd; ans2%=dd;
		}
		ans1=(ans1*vc)%dd; ans2=(ans2*vf)%dd;
		memset(nxt,0,sizeof(nxt));
		memset(a,0,sizeof(a));
		printf("%lld %lld\n",ans1,ans2);
	}
	return 0;
}
/*
1 0
16 12 1 1
000000000001
011111111111
000000000011
011111111111
010011111111
010111100011
010011101111
011111100011
111111111111
000011111111
011111111111
000000111111
011111000111
011111011111
011111000111
011111011111
谁给的恶臭样例？？？ 
*/
