#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define maxn 70
#define maxm 70
#define maxs 25
int sr,sg,sb,n,m,p,ans;
int rev[maxm][maxn],s[maxn],f[maxs][maxs][maxs];
bool flag[maxn];
inline int exgcd(int d,int f)
{
int x1 = 1,x2 = 0,x3 = f;
int y1 = 0,y2 = 1,y3 = d;
while (true)
{
if (y3 == 1) return (y2%f+f)%f;
int q = x3 / y3;
int t1 = x1 - q * y1,t2 = x2 - q * y2,t3 = x3 - q * y3;
x1 = y1; x2 = y2; x3 = y3;
y1 = t1; y2 = t2; y3 = t3;
}
}
inline int dp(int a)
{
memset(flag,false,sizeof(flag));
memset(f,0,sizeof(f));
int i,j,k,h,sz = 0,next;
for (i = 1;i <= n;++i)
if (!flag[i])
{
s[++sz] = 1;
flag[i] = true;
next = i;
while (!flag[rev[a][next]])
{
flag[rev[a][next]] = true;
s[sz]++;
next = rev[a][next];
}
}
f[0][0][0] = 1;
for (h = 1;h <= sz;++h)
for (i = sr;i >= 0;--i)
for (j = sb;j >= 0;--j)
for (k = sg;k >= 0;--k)
{
if (i >= s[h]) (f[i][j][k] += f[i-s[h]][j][k])%=p;
if (j >= s[h]) (f[i][j][k] += f[i][j-s[h]][k])%=p;
if (k >= s[h]) (f[i][j][k] += f[i][j][k-s[h]])%=p;
}
return f[sr][sb][sg];
}
int main()
{
freopen("1004.in","r",stdin);
freopen("1004.out","w",stdout);
scanf("%d %d %d %d %d",&sr,&sb,&sg,&m,&p); n = sr + sb + sg;
int i,j;
for (i = 1;i <= m;++i)
for (j = 1;j <= n;++j)
scanf("%d",rev[i]+j);
++m;
for (i = 1;i <= n;++i) rev[m][i] = i;
for (i = 1;i <= m;++i)
(ans += dp(i)) %= p;
printf("%d",ans*exgcd(m,p)%p);
fclose(stdin); fclose(stdout);
return 0;
}