#include #include using namespace std; using ll = long long; using mint = atcoder::modint; struct dsu { public: int csz; dsu() : _n(0) {} dsu(int n) : _n(n), csz(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); csz--; parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector> groups() { std::vector leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector& v) { return v.empty(); }), result.end()); return result; } int _n; // root node: -1 * component size // otherwise: parent std::vector parent_or_size; }; int main(){ vector>> A(26, vector>(26)); A[1][25] = {0,113246208,54525952,26214400,12582912,6029312,2883584,1376256,655360,311296,147456,69632,32768,15360,7168,3328,1536,704,320,144,64,28,12,5,2,1}; A[5][5] = {0,51380224,17301504,11501568,7749632,5599232,4361216,3564416,3023760,2603088,2265120,1971974,1703398,1448460,1194986,939036,687581,454452,258314,119182,42437,11295,2192,296,25,1}; A[1][24] = {0,54525952,26214400,12582912,6029312,2883584,1376256,655360,311296,147456,69632,32768,15360,7168,3328,1536,704,320,144,64,28,12,5,2,1}; A[2][12] = {0,29360128,11534336,9437184,6455296,4308992,2992128,2021376,1374592,929088,625544,419408,279656,185376,122088,80112,52888,35200,22416,12160,4967,1388,244,24,1}; A[4][6] = {0,25165824,8519680,5668864,3856384,2863104,2288896,1868032,1553240,1299184,1090650,919360,774295,643000,517972,394544,274893,167464,83894,32492,9316,1920,272,24,1}; A[1][23] = {0,26214400,12582912,6029312,2883584,1376256,655360,311296,147456,69632,32768,15360,7168,3328,1536,704,320,144,64,28,12,5,2,1}; ios::sync_with_stdio(false); cin.tie(0); int h, w; ll k; int m; cin >> h >> w >> k >> m; if (h > w) swap(h, w); mint::set_mod(m); vector tb(26); mint div; const int r = h * w; for(int i = 1; i <= 25; i++) tb[i] = mint(i).pow(k); for(int i = 1; i <= h * w; i++) div += mint(1) / i; dsu uf(h * w); auto f = [&](int S){ auto &&tmp = uf.parent_or_size; fill(tmp.begin(), tmp.end(), -1); int T = S; while(T){ int b = T & -T; T -= b; b = __lg(b); int y = b / w, x = b - y * w; if(x + 1 < w && (T >> (b + 1) & 1)) uf.merge(b, b + 1); if(y + 1 < h && (T >> (b + w) & 1)) uf.merge(b, b + w); } mint res; while(S){ int b = S & -S; S -= b; b = __lg(b); if (uf.leader(b) == b) res += tb[uf.size(b)]; } return res; }; mint ans; if(h * w >= 23){ for(int i = 1; i < A[h][w].size(); i++){ ans += A[h][w][i] * tb[i]; } }else{ for(int S = 1; S < (1 << (h * w)); S++) ans += f(S); } ans *= div; ans /= 1 << h * w; cout << ans.val() << '\n'; }