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