#include<iostream>
#include<cstring>
using namespace std;

long long T,id,n,m,c,f,ans1 = 0,ans2 = 0,b[1005][1005];
string a[1005];
long long check(long long x,long long y)
{
	long long ny = y;
	if(ny - 1 >= 0&&b[x][y - 1] != -1)
	{
		b[x][y] = b[x][y - 1] - 1;
		return b[x][y];
	}
	while(ny + 1 < m&&a[x][ny + 1] == '0')
		ny++;
	b[x][y] = ny - y;
	return ny - y;
}
long long checky(long long x,long long y)
{
	long long nx = x;
	while(nx + 1 <= n&&a[nx + 1][y] == '0')
		nx++;
	return nx - x;
}
void solve(long long x,long long y)
{
	long long sum1 = 0,sum2 = 0,sy = check(x,y),sx = checky(x,y);
	if(sy >= 1)
	{
		long long nx = x + 1;
		if(sx >= 3)
		{
			for(int i = 1;i < sx;i++)
				sum1 += check(x + i + 1,y) * sy;
			for(int i = 1;i < sx - 1;i++)
				sum2 += check(x + i + 1,y) * sy * (sx - 2);
		}
		else if(sx >= 2)
		{
			for(int i = 1;i < sx;i++)
				sum1 += check(x + i + 1,y) * sy;
		}
	}
	ans1 += sum1;
	ans1 %= 998244353;
	ans2 += sum2;
	ans2 %= 998244353;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%lld %lld",&T,&id);
	scanf("%lld %lld %lld %lld",&n,&m,&c,&f);
	for(int i = 1;i <= n;i++)
		cin>>a[i];
	memset(b,-1,sizeof(b));
	for(int i = 1;i <= n;i++)
		for(int l = 0;l < m;l++)
			if(a[i][l] != '1')solve(i,l);
	printf("%lld %lld",ans1 * c,ans2 * f);
}
