#include #include using namespace std; using mint = atcoder::modint; int main(){ int h, w; long long k; int m; cin >> h >> w >> k >> m; mint::set_mod(m); const int r = h * w; vector T(r), cnt(r + 1); for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ int v = y * w + x; if(y >= 1) T[v] |= 1 << v - w; if(y + 1 < h) T[v] |= 1 << v + w; if(x >= 1) T[v] |= 1 << v - 1; if(x + 1 < w) T[v] |= 1 << v + 1; } } mint ans, div; vector used(1 << r); for(int i = 0; i < r; i++) used[1 << i] = true; for(int S = 1; S < (1 << r); S++){ if(!used[S]) continue; int U = S, R = S, b, V; while(R){ R -= b = R & -R; U |= V = T[b = __lg(b)]; while(V){ used[S | V & -V] = true; V -= V & -V; } } cnt[__builtin_popcount(S)] += 1 << (r - __builtin_popcount(U)); } for(int i = 1; i <= r; i++){ ans += mint::raw(cnt[i]) * mint(i).pow(k); div += mint::raw(i).inv(); } ans *= div; ans /= 1 << r; cout << ans.val() << '\n'; }