#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define N 100100
using namespace std;
typedef long long LL;
typedef long double LD;
LL MOD;int n,m,Sb,Sr,Sg,vis[N],a[1100][1100],cnt[1010][1010],sum[1010][1010];
LL f[110][110][110];
LL powmod(LL x,LL P)
{LL e=x,res=1;for(;P;P>>=1) {if (P&1) res*=e,res%=MOD;e*=e,e%=MOD;}return res;}
LL a_1(LL x){return powmod(x,MOD-2);}
int dfs(int p,int x)
{
  if (vis[x])
  {
    int t=x,len=1;
    while (a[p][t]!=x) {len++;t=a[p][t];}
    return len;
  }
  vis[x]=1;
  return dfs(p,a[p][x]);
}
int main()
{
  ios::sync_with_stdio(false);
  scanf("%d%d%d%d%lld",&Sr,&Sb,&Sg,&m,&MOD);
  n=Sr+Sb+Sg;int i,j,k,p;
  FOR(i,1,m) 
  {
    FOR(j,1,n) scanf("%d",&a[i][j]);
    memset(vis,0,sizeof(vis));
    FOR(j,1,n) 
     if (!vis[j]) cnt[i][++cnt[i][0]]=dfs(i,j);
    FOR(j,1,cnt[i][0]) sum[i][j]=sum[i][j-1]+cnt[i][j];
  }
  LL ans=0,res=1,rr=1,rb=1,rg=1;
  FOR(i,1,n) res*=i,res%=MOD;
  FOR(i,1,Sr) rr*=i,rr%=MOD;FOR(i,1,Sb) rb*=i,rb%=MOD;FOR(i,1,Sg) rg*=i,rg%=MOD;
  ans+=res*a_1(rr)%MOD*a_1(rb)%MOD*a_1(rg)%MOD;
  FOR(p,1,m)
  {
    f[0][0][0]=1;memset(f,0,sizeof(f));
    FOR(k,0,cnt[p][0]-1) FOR(i,0,sum[p][k]) FOR(j,0,sum[p][k])
    {
      f[k+1][i+cnt[p][k+1]][j]+=f[k][i][j];f[k+1][i+cnt[p][k+1]][j]%=MOD;
      f[k+1][i][j+cnt[p][k+1]]+=f[k][i][j];f[k+1][i][j+cnt[p][k+1]]%=MOD;
      f[k+1][i][j]+=f[k][i][j];f[k+1][i][j]%=MOD;
    }
    ans+=f[cnt[p][0]][Sr][Sb],ans%=MOD;
  }
  printf("%lld\n",ans*a_1(m+1)%MOD);
  return 0;
}