#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e9;
const int INF = 2e9+5;
const int mod = 998244353;
char ch[1005];
int mp[6][1005][1005];
int s[6][1005][1005];
int read(){
	int f=1,x=0;
	char c;
	c=getchar();
	while(c>='9'||c<='0'){
		if(c=='-') f=-f;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return f*x;
}
void write(int x){
	if(x>9) write(x/10);
	x=putchar(x+48);
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t,id;
	scanf("%d%d",&t,&id);
	while(t--){
		int n,m,c,f;
		scanf("%d%d%d%d",&n,&m,&c,&f);
		if(f==0){
			if(c==0){
				printf("0 0");
				return 0;
			}
		}
		for(int i=1;i<=n;i++){
			cin>>ch;
			for(int j=m;j>0;j--){
				mp[t][i][j]=ch[j-1]-'0';
				if(mp[t][i][j]==0) s[t][i][j]=s[t][i][j+1]+1;
				else s[t][i][j]=0;
			}
		}
		ll vc=0,vf=0;
		for(int j=1;j<m;j++){
			int tmp=n;
			for(int i=n;i>=1;i--){
				if(mp[t][i][j]==1) tmp=i-1;
				else if(mp[t][i][j]==0){
					for(int q=i+2;q<=tmp;q++){
						vc+=(s[t][q][j]-1)%mod*(s[t][i][j]-1)%mod;
						vc%=mod;
						vf+=((s[t][q][j]-1)*(s[t][i][j]-1))%mod*(tmp-q);
						vf%=mod;
					}
				}
			}
		}
		vc=(vc*c)%mod;
		vf=(vf*f)%mod;
		printf("%lld %lld",vc,vf);
	}
	return 0;
}

