type
    strarr3 = array [1..3] of string;
var
    s: array[1..1000] of strarr3;
    ss: strarr3;
    tmpS: string;
    i, j, k, n: longint;
    len1: longint;
    count: longint;
begin
    assign(input, 'names.in');
    assign(output, 'names.out');
    reset(input);
    rewrite(output);

    readln(n);
    for i := 1 to n do begin
        readln(tmpS);
        len1 := pos(' ', tmpS);
        s[i, 1] := copy(tmpS, 1, len1 - 1);
        delete(tmpS, 1, len1);
        len1 := pos(' ', tmpS);
        s[i, 2] := copy(tmpS, 1, len1 - 1);
        delete(tmpS, 1, len1);
        s[i, 3] := tmpS;
    end;

    for i := 1 to n do begin
        count := 0;
        for j := 1 to n do begin
            for k := 1 to 3 do begin
                if s[i, 1] = s[j, k] then
                    inc(count);
            end;
        end;
        if count > 1 then begin
            {- IOF -> FIO -}
            tmpS := s[i, 3]; {- F -}
            s[i, 3] := s[i, 2];
            s[i, 2] := s[i, 1];
            s[i, 1] := tmpS;
        end;
    end;

    for i := 1 to n do
        for j := i + 1 to n do
            if s[i][1] > s[j][1] then begin
                ss := s[i];
                s[i] := s[j];
                s[j] := ss;
            end;

    for i := 1 to n do
        writeln(s[i, 1], ' ', s[i, 2], ' ', s[i, 3]);

    close(input);
    close(output);
end.
