program fuckyouquadruple;
var
fin,fout:text;
n,k,ans,i,j:longint;
a:array[1..100000] of 1..10;
b:array[1..100000,1..10] of longint;
function work(x:longint):longint;
var
i:longint;
begin
work:=0;
if x=0
then work:=1
else
for i:=1 to a[x] do
work:=(work+(work(b[x,i]) mod 1000000007)) mod 1000000007;
end;
begin
assign(fin,'three_squirrels.in');
assign(fout,'three_squirrels.out');
reset(fin);
rewrite(fout);
readln(fin,n);
ans:=0;
for i:=1 to n do
begin
read(fin,a[i]);
for j:=1 to a[i] do
read(fin,b[i,j]);
end;
ans:=work(n);
writeln(fout,ans);
close(fin);
close(fout);
end.