#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;#define N 55#define Mod 10000int n,m,s,t,k,x,y,nfish;int T[N],p[N][5];bool condi[N][N],flag[N][N];struct data{int a[N][N];}unit,st,A,trans[N],ans;data cheng(data a,data b){ data ans;memset(ans.a,0,sizeof(ans.a)); for (int k=1;k<=n;++k) for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j])%Mod; return ans;}data fast_pow(data a,int p){ data ans=unit; for (;p;p>>=1,a=cheng(a,a)) if (p&1) ans=cheng(ans,a); return ans;}int main(){ scanf("%d%d%d%d%d",&n,&m,&s,&t,&k);++s,++t; for (int i=1;i<=m;++i) { scanf("%d%d",&x,&y);++x,++y; flag[x][y]=flag[y][x]=1; } scanf("%d",&nfish); for (int i=1;i<=nfish;++i) { scanf("%d",&T[i]); for (int j=1;j<=T[i];++j) scanf("%d",&p[i][j]),++p[i][j]; } for (int i=1;i<=min(k,12);++i) for (int j=1;j<=nfish;++j) { int now=p[j][i%T[j]+1]; condi[i][now]=1; } for (int i=1;i<=n;++i) unit.a[i][i]=1; st.a[1][s]=1; for (int i=1;i<=min(k,12);++i) { for (int j=1;j<=n;++j) if (!condi[i][j]) for (int l=1;l<=n;++l) if (flag[l][j]) trans[i].a[l][j]=1; } A=unit; for (int i=1;i<=min(k,12);++i) A=cheng(A,trans[i]); if (k>12) { A=fast_pow(A,k/12); for (int i=1;i<=k%12;++i) A=cheng(A,trans[i]); } ans=cheng(st,A); PRintf("%d/n",ans.a[1][t]);}