#include<cstdio>
#include<vector>
#include<cstring>
#define N 100010
#define CK 1000000007
using namespace std;
int i,n,k,j,x;
int s[N],z[N],d[N];
vector <int> l[N];
inline int read(){
int p=0,c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') p=p*10+c-48,c=getchar();
return p;
}
inline void Work(){
int i=0,t=1;
z[++z[0]]=0; s[0]=1;
while (t<=z[0]){
for (i=0;i<l[z[t]].size();i++){
s[l[z[t]][i]]=(s[l[z[t]][i]]+s[z[t]])%CK;
d[l[z[t]][i]]--;
if (!d[l[z[t]][i]]) z[++z[0]]=l[z[t]][i];
}
t++;
}
printf("%d\n",s[n]);
}
int main(){
freopen("three_squirrels.in","r",stdin);
freopen("three_squirrels.out","w",stdout);
n=read();
for (i=1;i<=n;i++){
k=read();
for (j=1;j<=k;j++){
x=read(); l[x].push_back(i); d[i]++;
}
}
Work();
return 0;
}