type node=record
v,q:longint;
end;
var lu:array[1..10000000] of node;
f:array[0..100100] of int64;
i,n,k,x,tot:longint;
mo:int64;
function dfs(t:longint):int64;
var next:longint;
begin
if f[t]<>-1 then exit(f[t]);
f[t]:=0;
next:=h[t];
while next<>0 do
begin
f[t]:=(f[t]+dfs(lu[next].v)) mod mo;
next:=lu[next].q;
end;
exit(f[t]);
end;
begin
assign(input,'three_squirrels.in');
assign(output,'three_squirrels.out');
reset(input);
rewrite(output);
mo:=1000000007;
read(n);
for i:=1 to n do
begin
read(k);
for j:=1 to k do
begin
read(x);
inc(tot);
lu[tot].v:=x;lu[tot].q:=h[i];h[i]:=tot;
end;
end;
fillchar(f,sizeof(f),255);
f[0]:=1;
writeln(dfs(n));
close(input);
close(output);
end.