#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=1;--i)
#define N 1005
#define int long long
using namespace std;

int read(){
	int x=0,w=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*w;
}

const int mod = 998244353;
int n,m,T,id,f,c;
int hen[N][N],shu[N][N],che[N][N];
char mp[N][N];

signed main(){
	
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	
	T=read(); id=read();
	n=read(); m=read(); c=read(); f=read();
	rep(i,1,n) scanf("%s",mp[i]+1);
	rep(i,1,n) per(j,m,1){
		if(mp[i][j]=='1') hen[i][j]=0;
		else hen[i][j]=hen[i][j+1]+1;
	}
	per(i,n,1) rep(j,1,m){
		if(mp[i][j]=='1') shu[i][j]=0;
		else shu[i][j]=shu[i+1][j]+1;
	}
	rep(i,1,n) rep(j,1,m){
		if(mp[i][j]=='1') che[i][j]=0;
		else che[i][j]=che[i-1][j]+hen[i][j]-1;
	}
	int ans1=0,ans2=0;
	rep(i,3,n) rep(j,1,m){
		if(mp[i][j]=='1') continue;
		if(mp[i-1][j]=='0'){
			ans1=(ans1+(hen[i][j]-1)*che[i-2][j])%mod;
			ans2=(ans2+(hen[i][j]-1)*che[i-2][j]%mod*shu[i+1][j]%mod)%mod;
		}
	}
	printf("%lld %lld\n",ans1*c%mod,ans2*f%mod);
	return 0;
}