#include using namespace std; using ll=long long; using ld=long double; using vi=vector; using vl=vector; using pii=pair; using pll=pair; templateusing pqg=priority_queue,greater>; #define all(x) begin(x),end(x) #define rall(x) rbegin(x),rend(x) #define sz(x) (int)x.size() #define rep(i,a,b) for(int i=a;i=b;i--) const ll INF=4e18; const int MOD=1e9+7; const int MOD2=998244353; ll modpow(ll a,ll b,ll m=MOD){ ll r=1; while(b){ if(b&1)r=r*a%m; a=a*a%m; b>>=1; } return r; } struct DSU{ vi p,s; DSU(int n){p.resize(n);s.assign(n,1);iota(all(p),0);} int find(int x){return p[x]==x?x:p[x]=find(p[x]);} bool join(int a,int b){a=find(a);b=find(b);if(a==b)return 0;if(s[a]>g;vi lv,it; Dinic(int n):n(n),g(n),lv(n),it(n){} void add(int a,int b,ll c){ g[a].push_back({b,(int)g[b].size(),c}); g[b].push_back({a,(int)g[a].size()-1,0}); } bool bfs(int s,int t){ fill(all(lv),-1); queueq;q.push(s);lv[s]=0; while(q.size()){ int x=q.front();q.pop(); for(auto&e:g[x])if(e.cap&&lv[e.to]<0)lv[e.to]=lv[x]+1,q.push(e.to); } return lv[t]>=0; } ll dfs(int x,int t,ll f){ if(x==t)return f; for(int&i=it[x];i prefix(string s){ vectorp(sz(s)); rep(i,1,sz(s)){ int j=p[i-1]; while(j&&s[i]!=s[j])j=p[j-1]; if(s[i]==s[j])j++; p[i]=j; } return p; } vector zfunc(string s){ int n=sz(s),l=0,r=0; vectorz(n); rep(i,1,n){ if(i<=r)z[i]=min(r-i+1,z[i-l]); while(i+z[i]r)l=i,r=i+z[i]-1; } return z; } struct SAM{ struct Node{int nxt[26],link,len;Node(){memset(nxt,-1,sizeof(nxt));link=-1;len=0;}}; vectorst;int last; SAM(){st.push_back(Node());last=0;} void add(char c){ int cur=sz(st);st.push_back(Node());st[cur].len=st[last].len+1; int p=last; while(p!=-1&&st[p].nxt[c-'a']==-1){st[p].nxt[c-'a']=cur;p=st[p].link;} if(p==-1)st[cur].link=0; else st[cur].link=st[p].nxt[c-'a']; last=cur; } }; struct Point{ ld x,y; Point(){} Point(ld x,ld y):x(x),y(y){} Point operator-(Point p){return {x-p.x,y-p.y};} ld cross(Point p){return x*p.y-y*p.x;} }; void solve(){ int h, w; if(!(cin >> h >> w)) return; int sx, sy, gx, gy; ll k; cin >> sx >> sy >> gx >> gy >> k; sx--; sy--; gx--; gy--; int n = h * w; int s = sx * w + sy; int g = gx * w + gy; auto can = [&](int u, int v){ if(u == v) return false; int x1 = u / w, y1 = u % w; int x2 = v / w, y2 = v % w; if(x1 == x2 || y1 == y2) return true; if(abs(x1 - x2) == abs(y1 - y2)) return true; return false; }; ll q = k / n; int r = k % n; vector> dp(n, vector(1 << n, vl(n, 0))); rep(u, 0, n){ rep(v, 0, n){ if(can(u, v)){ dp[u][1 << v][v] = 1; } } rep(mask, 1, 1 << n){ int cnt = __builtin_popcount(mask); if(cnt >= n) continue; rep(v, 0, n){ if(!dp[u][mask][v]) continue; rep(nxt, 0, n){ if(!(mask & (1 << nxt)) && can(v, nxt)){ dp[u][mask | (1 << nxt)][nxt] = (dp[u][mask | (1 << nxt)][nxt] + dp[u][mask][v]) % MOD2; } } } } } using Mat = vector; Mat a(n, vl(n, 0)); rep(u, 0, n){ rep(v, 0, n){ a[u][v] = dp[u][(1 << n) - 1][v]; } } auto mul = [&](const Mat& x, const Mat& y){ Mat z(n, vl(n, 0)); rep(i, 0, n){ rep(j, 0, n){ rep(l, 0, n){ z[i][j] = (z[i][j] + x[i][l] * y[l][j]) % MOD2; } } } return z; }; auto matpow = [&](Mat x, ll p){ Mat res(n, vl(n, 0)); rep(i, 0, n) res[i][i] = 1; while(p > 0){ if(p & 1) res = mul(res, x); x = mul(x, x); p >>= 1; } return res; }; Mat Mq = matpow(a, q); if(r == 0){ cout << Mq[s][g] << "\n"; return; } Mat b(n, vl(n, 0)); rep(u, 0, n){ rep(mask, 1, 1 << n){ if(__builtin_popcount(mask) == r){ rep(v, 0, n){ b[u][v] = (b[u][v] + dp[u][mask][v]) % MOD2; } } } } Mat ans = mul(Mq, b); cout << ans[s][g] << "\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T=1; while(T--)solve(); }