begin
readln(n);
fillchar(map,sizeof(map),0);
for i:=1 to n do
begin
readln(y1[i],x1[i],y2[i],x2[i],color[i]);
for j:=y1[i] to y2[i] do
for k:=x1[i] to x2[i] do
map[j,k]:=i;
end;
fillchar(father,sizeof(father),0);
for i:=0 to 99 do
begin
if map[i,1]=0 then break else
for j:=0 to 99 do
begin
if map[i,j]=0 then break else
if (map[i,j]>0)and(map[i+1,j]>0)and(map[i,j]<>map[i+1,j]) then
father[map[i+1,j],map[i,j]]=true;
end;
end;
root[0]:=0; k:=1;
for i:=0 to 99 do
if (map[1,i]<>map[1,i-1]) then
begin
root[k]:=map[1,i-1];
root[k+1]:=map[1,i];
if map[1,i]<>0 then inc(root[0]) else break;
end;
dfs();
end.
readln(n);
fillchar(map,sizeof(map),0);
for i:=1 to n do
begin
readln(y1[i],x1[i],y2[i],x2[i],color[i]);
for j:=y1[i] to y2[i] do
for k:=x1[i] to x2[i] do
map[j,k]:=i;
end;
fillchar(father,sizeof(father),0);
for i:=0 to 99 do
begin
if map[i,1]=0 then break else
for j:=0 to 99 do
begin
if map[i,j]=0 then break else
if (map[i,j]>0)and(map[i+1,j]>0)and(map[i,j]<>map[i+1,j]) then
father[map[i+1,j],map[i,j]]=true;
end;
end;
root[0]:=0; k:=1;
for i:=0 to 99 do
if (map[1,i]<>map[1,i-1]) then
begin
root[k]:=map[1,i-1];
root[k+1]:=map[1,i];
if map[1,i]<>0 then inc(root[0]) else break;
end;
dfs();
end.