{
TASK:folders
LANG:PASCAL
}
{$S-}
type ident=Record
       name:String;
       address:String;
       parent:Byte;
       childnr:Byte;
       timc:Longint;
     End;
var line:Array[1..200]of string;
    a:Array[0..200] of ident;
    b:Array[0..200] of ident;
    s,s1,s2:String;
    i,j,c,m,posb,brchange,b1,b2:Longint;
    code:Integer;
    found:Boolean;
Procedure AddChange;
Begin
  brchange:=brchange+1;
  {    WriteLn('On A');
       WriteLn('Name:'+a[b1].name);
       str(a[b1].childnr,s1);
       WriteLn('Children:'+s1);
       str(a[b1].timc,s1);
       WriteLn('Time:'+s1);
       WriteLn('Address:'+a[b1].address);
       WriteLn('On B');
       WriteLn('Name:'+b[b2].name);
       str(b[b2].childnr,s1);
       WriteLn('Children:'+s1);
       str(b[b2].timc,s1);
       WriteLn('Time:'+s1);
       WriteLn('Address:'+b[b2].address);}
End;
Procedure SpecialRead(pnum:Byte);
var k:Byte;
    s:String;
    place:Byte;
Begin
  i:=i+1;
  place:=i;
  ReadLn(s);
  s1:=s;
  a[i-posb].name:=copy(s1,1,pos(' ',s1)-1);
  delete(s1,1,pos(' ',s1));
  s2:=copy(s1,1,pos(' ',s1)-1);
  val(s2,m,code);
  a[i-posb].childnr:=m;
  delete(s1,1,pos(' ',s1));
  val(s1,a[i-posb].timc,code);
  a[i-posb].parent:=pnum;
  a[i-posb].address:=a[a[i-posb].parent].address+'\'+a[i-posb].name;
 if a[i-posb].childnr>0 then
 for k:=1 to a[i-posb].childnr do
 Begin
   SpecialRead(place);
 End;
End;
Procedure SpecialRead2(pnum:Byte);
var k:Byte;
    s:String;
    place:Byte;
Begin
  i:=i+1;
  place:=i;
  ReadLn(s);
  s1:=s;
  b[i-posb].name:=copy(s1,1,pos(' ',s1)-1);
  delete(s1,1,pos(' ',s1));
  s2:=copy(s1,1,pos(' ',s1)-1);
  val(s2,m,code);
  b[i-posb].childnr:=m;
  delete(s1,1,pos(' ',s1));
  val(s1,b[i-posb].timc,code);
  b[i-posb].parent:=pnum;
  b[i-posb].address:=b[b[i-posb].parent].address+'\'+b[i-posb].name;
 if b[i-posb].childnr>0 then
 for k:=1 to b[i-posb].childnr do
 Begin
   SpecialRead2(place-posb);
 End;
End;
Begin
  i:=0;
  SpecialRead(0);
  posb:=i;
  SpecialRead2(0);
  brchange:=0;
 For b1:=1 to posb do
 Begin
   found:=false;
  for b2:=1 to (i-posb) do
  if b[b2].address=a[b1].address then
  Begin
    found:=true;
    Break;
  End;
  If found then
  Begin
   if b[b2].childnr=0 then
   Begin
    if a[b1].childnr>0 then
    Begin
       addchange;
       continue;
    End;
    if b[b2].timc<a[b1].timc then
     Begin
       addchange;
       continue;
     End;
   End;
  End
  else
  Begin
    brchange:=brchange+1;
    {WriteLn(a[b1].name,' ne e otkrita v B');}
    continue;
  End;
 End;
   WriteLn(brchange);
 { For b1:=1 to posb do
   WriteLn(a[b1].address);
  For b2:=1 to i-posb do
   WriteLn(b[b2].address);}
End.
