#ifndef TheCodeWasMadeByMooos
#define TheCodeWasMadeByMooos
#include<bits/stdc++.h>
#define endl '\n'
#define QAQ(n, m) for(ll i = n; i <= m; ++i)
#define QWQ(n, m) for(ll j = n; j <= m; ++j)
#define For(i, n, m) for(ll i = n; i <= m; ++i)
#define uQWQ(n, m) for(ll j = n; j >= m; --j)
#define uQAQ(n, m) for(ll i = n; i >= m; --i)
#define uFor(i, n, m) for(ll i = n; i >= m; --i)
#define FOpen(x) freopen (#x".in", "r", stdin), freopen (#x".out", "w", stdout)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll mod = 998244353;
ll n, m, c, f, AnsC, AnsF, T, id;
ll Mp[1010][1010], Prex[1010][1010], Pre[1010][1010], PreC[1010][1010];
string s;

int main () {
	FOpen (plant), cin.tie (0), ios::sync_with_stdio (false);
	cin >> T >> id >> n >> m >> c >> f;
	QAQ (1, n) {
		cin >> s;
		QWQ (0, m - 1) Mp[i][j + 1] = s[j] - '0';
		uQWQ (m, 1) Prex[i][j] = (Mp[i][j] ? 0 : Prex[i][j + 1] + 1);
	}
	QAQ (1, n) QWQ (1, m) if (!Mp[i][j])
		Pre[i][j] = Pre[i - 1][j] + Prex[i][j] - 1;
	QAQ (3, n) QWQ (1, m) {
		if (!Mp[i][j] && !Mp[i - 1][j] && !Mp[i - 2][j])
			AnsC = (AnsC + (Prex[i][j] - 1) * (Pre[i - 2][j]) % mod) % mod,
			PreC[i][j] = (PreC[i - 1][j] + (Prex[i][j] - 1) * Pre[i - 2][j] % mod) % mod;
		if (!Mp[i][j] && !Mp[i - 1][j])
			AnsF = (AnsF + PreC[i - 1][j]) % mod;
	}
	cout << AnsC * c << ' ' << AnsF * f << endl;
}
#endif