const
  Inp1  = 'inpit1.txt';
  Inp2  = 'input2.txt';
  Out1  = 'output1.txt';
type
 Pty = ^ty;
 ty = record
   name1 : String[10];
   Name2 : String[10];
   next : Pty;
 end;
var
  Root1,Root2             : Pty;
  f1,f2                   : text;
{==========================================}{P1}
Procedure ReadM(var root : pty;inp : string);
var
Tec,Pred : Pty;
S        : string;
I        : integer;
begin
  Assign(f1,Inp);
  Reset(f1);
  New(tec);
  Readln(f1,S);
  I := Pos(' ',S);
  if I > 10 Then Begin
     Write('Too Long name');
     Halt(255);
  end;
  Tec^.Name1 := Copy(S,1,I-1);

  if Length(s)-I > 10 Then begin
     Write('Too Long Surname');
     Halt(255);
  end;

  Tec^.Name2 := Copy(S,I+1,Length(S)-I);

  Root := Tec;
  Root^.next := nil;
  Pred := Tec;
  While not(Eof(F1)) do begin
    New(Tec);
    Readln(f1,S);
    I := Pos(' ',S);
    if I > 10 Then Begin
       Write('Too Long name');
       Halt(255);
    end;
    Tec^.Name1 := Copy(S,1,I-1);

    if Length(s)-I > 10 Then begin
     Write('Too Long Surname');
     Halt(255);
    end;

    Tec^.Name2 := Copy(S,I+1,Length(S)-I);
    Pred^.next := Tec;
    Pred := Tec;
    Tec^.Next := nil;
  end;
  close(f1);
end;
{==========================================}
{==========================================}    {p2}
Procedure OuttoFils(Root : pty;Out : string);
begin
  Assign(F2,Out);
  ReWrite(f2);

  while root<>nil do Begin
    WriteLn(f2,Root^.name1,' ',Root^.name2);
    root := root^.next;
  end;

  close(f2);
end;
{==========================================}
Procedure P3(Var Root1,Root2 : pty);      {p3}
var
Tec,Sled,Pred : Pty;
begin
 Tec := Root2;
 While Tec <> Nil do begin
   If (Tec^.name1 = Root1^.name1) and (Tec^.name2 = Root1^.name2) Then
   begin
     Sled := Root1;
     Root1 := Root1^.next;
     dispose(Sled);
   end
   else begin
     Pred := Root1;
     Sled := Root1^.next;
     While Sled<> Nil do begin
       If (Tec^.name1 = Sled^.name1) and (Tec^.name2 = Sled^.name2) Then
       begin
          Pred^.next := Sled^.next;
          Dispose(Sled);
          Sled := Pred^.next;
       end
       else begin
         Pred := Sled;
         Sled := Sled^.next;
       end;
     end;
     Tec := Tec^.next;
   end;
 end;
end;
{==========================================}
begin
  ReadM(Root1,inp1);
  ReadM(Root2,inp2);
  P3(Root1,Root2);
  OuttoFils(Root1,Out1);
end.