#include<bits/stdc++.h>
#define ll long long
const ll mod=998244353;
template <typename T> void read(T &x){
	T sign=1,sum=0;
	char c=getchar();
	while (!isdigit(c)){
		if (c=='-'){
			sign=-1;
		}
		c=getchar();
	}
	while (isdigit(c)){
		sum=(sum<<1)+(sum<<3)+c-'0';
		c=getchar();
	}
	x=sign*sum;
}
const int N=2005;
int T,id;
int n,m;
ll c,f;
int a[N][N];
ll sum[N][N];
ll sum1[N][N];
ll sum2[N][N];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	read(T),read(id);
	read(n),read(m),read(c),read(f);
	c%=mod,f%=mod;
	for (int i=1;i<=n;++i){
		for (int j=1;j<=m;++j){
			char c=getchar();
			a[i][j]=c-'0';
		}
		char c=getchar();
	}
	for (int i=1;i<=n;++i){
		sum[i][m+1]=-1;
		for (int j=m;j>=1;--j){
			if (a[i][j]){
				sum[i][j]=-1;
				continue;
			}
			sum[i][j]=sum[i][j+1]+1;
			sum[i][j]%=mod;
		}
	}
	ll ans_c=0;
	for (int j=1;j<=m;++j){
		ll tmp1=sum[1][j];
		for (int i=2;i<=n;++i){
			if (a[i][j]){
				tmp1=0;
				continue;
			}
			if (a[i-1][j]){
				tmp1=sum[i][j];
			}
			else{
				ans_c+=(tmp1-sum[i-1][j])*sum[i][j]%mod;
				ans_c=ans_c%mod;
				sum1[i][j]=(tmp1-sum[i-1][j])*sum[i][j]%mod;
				tmp1+=sum[i][j];
				tmp1%=mod;
			}
		}
	}
	ll ans_f=0;
	for (int j=1;j<=m;++j){
		for (int i=n;i>=1;--i){
			if (a[i][j]){
				sum2[i][j]=0;
				continue;
			}
			sum2[i][j]=sum2[i+1][j]+1;
			ans_f+=sum2[i+1][j]*sum1[i][j]%mod;
			ans_f%=mod;                   
			sum2[i][j]%=mod;
		}
	}
	printf("%lld %lld\n",(ans_c*c)%mod,(ans_f*f)%mod);
}