#include<bits/stdc++.h> usingnamespace std; typedeflonglong lnt; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, m, A, B, C, num; int p[65], cnt[65], tot[65]; lnt f[65][65][65], pw[65], P; bool mrk[65]; lnt inv(lnt x){ lnt ret = 1; for (lnt k = P-2; k; k >>= 1, x = x*x%P) if (k&1) ret = ret*x%P; return ret; } voidDFS(int u, int sz){ if (mrk[u]) {cnt[++num] = sz; return;} mrk[u] = true, DFS(p[u], sz+1); } intmain(){ read(A), read(B), read(C), n = A+B+C, read(m), read(P); pw[0] = 1; for (int i = 1; i <= n; i++) pw[i] = pw[i-1]*i%P; lnt sum = pw[n]*inv(pw[A])%P*inv(pw[B])%P*inv(pw[C])%P; for (int T = 1; T <= m; T++) { num = 0; memset(mrk, false, sizeof mrk); for (int i = 1; i <= n; i++) read(p[i]); for (int i = 1; i <= n; i++) if (!mrk[i]) DFS(i, 0); for (int i = 1; i <= num; i++) tot[i] = tot[i-1]+cnt[i]; for (int i = 1; i <= num; i++) for (int a = 0; a <= A; a++) for (int b = 0; b <= B; b++) { int c = tot[i]-a-b; f[i][a][b] = 0; if (a >= cnt[i]) (f[i][a][b] += f[i-1][a-cnt[i]][b]) %= P; if (b >= cnt[i]) (f[i][a][b] += f[i-1][a][b-cnt[i]]) %= P; if (c >= cnt[i]) (f[i][a][b] += f[i-1][a][b]) %= P; } (sum += f[num][A][B]) %= P; } returnprintf("%lld\n", sum*inv(m+1)%P), 0; }