#include using namespace std; #include using namespace atcoder; using mint = modint998244353; using vm = vector; using vvm = vector; inline ostream &operator<<(ostream &os, const mint x) { return os << x.val(); }; inline istream &operator>>(istream &is, mint &x) { long long v; is >> v; x = v; return is; }; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--) #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using vb = vector; using vvb = vector; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; template ostream &operator<<(ostream &os, pair &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template ostream &operator<<(ostream &os, vector &vec) { for (int i = 0; i < (int)vec.size(); i++) { os << vec[i] << (i + 1 == (int)vec.size() ? "" : " "); } return os; } template istream &operator>>(istream &is, vector &vec) { for (int i = 0; i < (int)vec.size(); i++) is >> vec[i]; return is; } ll floor(ll a, ll b) { return a >= 0 ? a / b : (a + 1) / b - 1; } ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; } int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; void solve() { int h, w, m; ll k; cin >> h >> w >> k >> m; if (h < w) swap(h, w); using mint = dynamic_modint<0>; mint::set_mod(m); vector rev(1 << w, 0); rep(v, 0, 1 << w) rep(i, 0, w) rev[v] |= ((v >> i) & 1) << (w - 1 - i); int mask = (1 << w) - 1; int mask1 = 0; rep(i, 0, h) mask1 |= 1 << (w * i); int mask_all = (1 << (h * w)) - 1; vector cnt(h * w + 1, 0); vector ok(1 << (h * w), false); int vc[] = {0, 0, 0, 0}; rep(bit, 1, 1 << (h * w)) { int rbit = 0; rep(i, 0, h) rbit |= rev[(bit >> (i * w)) & mask] << (i * w); int cbit = 0; rep(i, 0, h) cbit |= ((bit >> (i * w)) & mask) << ((h - 1 - i) * w); int rcbit = 0; rep(i, 0, h) rcbit |= rev[(bit >> (i * w)) & mask] << ((h - 1 - i) * w); if (bit <= rbit && bit <= cbit && bit <= rcbit) { int v = 0, cm = 0; rep(i, 0, h + 1) rep(j, 0, w) { int u = w * i + j; int z = (v >> (j * 2)) & 3; if ((bit >> u) & 1) { if (z) { int y = j ? ((v >> (j * 2 - 2)) & 3) : 0; if (y > 0 && y != z) { rep(x, 0, w) if (((v >> (x * 2)) & 3) == y) { v ^= ((y ^ z) << (x * 2)); vc[y]--; vc[z]++; } } } else { int y = j ? (v >> (j * 2 - 2)) & 3 : 0; if (y) { z = y; } else { z = 1; while (vc[z]) z++; } vc[z]++; v |= z << (j * 2); } } else { if (vc[z] == 1) cm++; vc[z]--; v &= ~(3 << (j * 2)); } } ok[bit] = cm == 1; ok[rbit] = ok[bit]; ok[cbit] = ok[bit]; ok[rcbit] = ok[bit]; if (!ok[bit]) continue; set st; st.insert(bit); st.insert(rbit); st.insert(cbit); st.insert(rcbit); int val = (int)st.size(); int pc = __builtin_popcount(bit); int c = 0; int nbit = (bit >> w) | ((bit << w) & mask_all) | ((bit & ~mask1) >> 1) | ((bit << 1) & ~mask1); rep(z, 0, h * w) { if ((bit >> z) & 1) continue; c += (nbit >> z) & 1; } cnt[pc] += val << (h * w - pc - c); } } mint ans = 0; rep(i, 0, h * w + 1) ans += mint(i).pow(k) * cnt[i]; mint p = 0; rep(i, 1, h * w + 1) p += mint(i).inv(); ans *= p; ans *= mint(2).inv().pow(h * w); cout << ans.val() << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }