import java.io.*;
import java.util.*;

public class names_ak_java {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new File("names.in"));
        int n = in.nextInt();
        String[][] s = new String[n][3];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < 3; j++)
                s[i][j] = in.next();
        HashMap<String, Integer> counts = new HashMap<>();
        for (String[] fio : s) {
            for (String name : fio) {
                if (!counts.containsKey(name)) {
                    counts.put(name, 1);
                } else {
                    counts.put(name, counts.get(name) + 1);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (counts.get(s[i][0]) > 1) {
                // IOF -> FIO
                s[i] = new String[] {s[i][2], s[i][0], s[i][1]};
            }
        }

        Arrays.sort(s, new Comparator<String[]>() {
            @Override
            public int compare(String[] fio1, String[] fio2) {
                return fio1[0].compareTo(fio2[0]);
            }
        });
        
        PrintWriter out = new PrintWriter("names.out");
        for (String[] fio : s)
            out.println(fio[0] + " " + fio[1] + " " + fio[2]);
        out.close();
    }
}
