program domino;

  const PRF='DOMINO.DAT';
        RZF='DOMINO.REZ';
  var pf, rf: text;

  procedure delioti;
    var n, k, d, i, x, y: integer;
        padeta: boolean;
  begin
    readln (pf, n);
    readln (pf, k, d);
    n := n - 1;
    writeln (rf, k, ' ', d);
    i := 1; padeta := true;
    while (i <= n) and padeta do
      begin
         readln (pf, x, y);
         if (x = k) or (y = k)
            then begin
                   writeln (rf,'K');
                   if x = k then k := y
                            else k := x;
                 end
         else if (x = d) or (y = d)
            then begin
                   writeln (rf, 'D');
                   if x = d then d := y
                            else d := x;
                 end
         else padeta := false;
        i := i + 1
      end;
  end;

begin
  assign (pf, PRF);
  reset (pf);
  assign (rf, RZF);
  rewrite (rf);
  delioti;
  close (pf);
  close (rf);
end.
