#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } using mint = atcoder::modint998244353; void solve() { int h, w, sx, sy, gx, gy; ll K; cin >> h >> w >> sx >> sy >> gx >> gy >> K; sx--, sy--, gx--, gy--; vector dx = {1, 1, 1, 0, -1, -1, -1, 0}; vector dy = {1, 0, -1, -1, -1, 0, 1, 1}; auto isin = [&](int x, int y) { return 0 <= x && x < h && 0 <= y && y < w; }; auto decode = [&](int x) { return pair(x / w, x % w); }; auto encode = [&](int x, int y) { return x * w + y; }; int n = h * w; int stid = encode(sx, sy); int glid = encode(gx, gy); vector pw(n, vector(n)); vector sm(n, 0); rep(st, 0, n) { vector vv(n, vector(1 << n)); vv[st][0] = 1; rep(bit, 0, 1 << n) rep(i, 0, n) if (vv[i][bit] != 0) { auto [x, y] = decode(i); rep(d, 0, 8) { int nx = x + dx[d], ny = y + dy[d]; while (isin(nx, ny)) { int z = encode(nx, ny); if (!((bit >> z) & 1)) vv[z][bit | (1 << z)] += vv[i][bit]; nx += dx[d], ny += dy[d]; } } } rep(i, 0, n) pw[st][i] = vv[i].back(); rep(bit, 0, 1 << n) if (popcount(1ULL * bit) == K % n) { sm[st] += vv[glid][bit]; } } vector dp(n, vector(1 << n)); dp[glid][1 << glid] = 1; rep(bit, 0, 1 << n) rep(i, 0, n) if (dp[i][bit] != 0) { auto [x, y] = decode(i); rep(d, 0, 8) { int nx = x + dx[d], ny = y + dy[d]; while (isin(nx, ny)) { int z = encode(nx, ny); if (!((bit >> z) & 1)) dp[z][bit | (1 << z)] += dp[i][bit]; nx += dx[d], ny += dy[d]; } } } auto mul = [&](const vector>& a, const vector>& b) { vector c(n, vector(n)); rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) c[i][k] += a[i][j] * b[j][k]; return c; }; vector ar(n, vector(n)); rep(i, 0, n) ar[i][i] = 1; K /= n; while (K) { if (K & 1) ar = mul(ar, pw); pw = mul(pw, pw); K /= 2; } mint ans = 0; rep(i, 0, n) ans += ar[stid][i] * sm[i]; cout << ans.val() << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }