#include <cstdio>
#include <cstring>
#include <climits>
#include <vector>
#include <algorithm>
const int MAX_X = 20;
const int MAX_N = 60;
const int MAX_M = 60;
int a, b, c, n, m, mod;
inline int calc(int *map) {
bool flag[MAX_M + 1] = { false };
std::vector<int> v;
for (int i = 1; i <= n; i++) {
int x = 0;
for (int j = i; !flag[j]; j = map[j]) {
flag[j] = true;
x++;
}
if (x) v.push_back(x);
}
static int f[MAX_X + 1][MAX_X + 1][MAX_X + 1];
memset(f, 0, sizeof(f));
f[0][0][0] = 1;
for (std::vector<int>::const_iterator it = v.begin(); it != v.end(); it++) {
for (int i = a; i >= 0; i--) {
for (int j = b; j >= 0; j--) {
for (int k = c; k >= 0; k--) {
if (i >= *it) (f[i][j][k] += f[i - *it][j][k]) %= mod;
if (j >= *it) (f[i][j][k] += f[i][j - *it][k]) %= mod;
if (k >= *it) (f[i][j][k] += f[i][j][k - *it]) %= mod;
}
}
}
}
return f[a][b][c];
}
inline void exgcd(int a, int b, int &g, int &x, int &y) {
if (!b) g = a, x = 1, y = 0;
else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
inline int inv(int x) {
int g, r, y;
exgcd(x, mod, g, r, y);
return (r % mod + mod) % mod;
}
int main() {
scanf("%d %d %d %d %d", &a, &b, &c, &m, &mod);
n = a + b + c;
static int map[MAX_N + 1];
int sum = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) scanf("%d", &map[j]);
(sum += calc(map)) %= mod;;
}
for (int i = 1; i <= n; i++) map[i] = i;
(sum += calc(map)) %= mod;
int ans = sum * inv(m + 1) % mod;
printf("%d\n", ans);
return 0;
}