program pil_10_17_b(input,output);
const
  n = 30;
  k = 8;
type
  str = packed array [1..k] of char;
var
  mas : array [1..n] of str;
  last, cur, template : str;
  c, pred : char;
  i, j, All : integer;
  flag, tmp : boolean;
begin
  for i:=1 to k do
    template[i] := ' ';
  {input data}
  i := 1;
  repeat
    read(c);
    j := 1;
    mas[i] := template;
    while (c<>'.')and(c<>',') do begin
      mas[i,j] := c;
      j := j+1;
      read (c);
    end;
    i := i+1;
  until c='.';
  All := i-1;
  last := mas[All];
  for i:=1 to All-1 do begin
    cur := mas[i];
    if cur<>last then begin
      pred := cur[1];
      j := 2;
      flag := true;
      tmp := false;
      while (j<=k)and flag and (not tmp) do begin
        tmp := cur[j]=' ';
        if not tmp then flag := cur[j]>pred;
        pred := cur[j];
        j := j+1;
      end;
      if flag then WriteLn(cur);
    end;
  end;
end.
