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

public class Validate {

    final static long MAX_LEN = 20;
    final static long MAXN = 1000;

    public static boolean isLower(char ch) {
        return 'a' <= ch && ch <= 'z';
    }

    public static boolean isUpper(char ch) {
        return 'A' <= ch && ch <= 'Z';
    }

    public static boolean isName(String s) {
        if (!isUpper(s.charAt(0)))
            return false;
        for (int i = 1; i < s.length(); i++) {
            if (!isLower(s.charAt(i)))
                return false;
        }
        return true;
    }

    public void run() {
        StrictScanner inf = new StrictScanner(System.in);
        int n = inf.nextInt();
        ensureLimits(n, 2, MAXN, "n");
        inf.nextLine();
        String[][] ss = new String[n][3];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                ss[i][j] = inf.next();
                ensureLimits(ss[i][j].length(), 1, MAX_LEN, "s[" + i + "][" + j + "].len()");
                ensure(isName(ss[i][j]), "English letters");
            }
            inf.nextLine();
        }

        HashMap<String, Integer> count = new HashMap<>();
        for (String[] sx : ss) {
            for (String s : sx) {
                if (!count.containsKey(s)) {
                    count.put(s, 1);
                } else {
                    count.put(s, count.get(s) + 1);
                }
            }
        }

        for (int i = 0; i < n; i++) {
            if (count.get(ss[i][0]) > 1) {
                // IOF -> FIO
                ss[i] = new String[] {ss[i][2], ss[i][0], ss[i][1]};
            }
        }

        HashSet<String> lastNames = new HashSet<>();
        for (String[] sx : ss)
            lastNames.add(sx[0]);

        ensure(lastNames.size() == n, "last names are unique");

        HashMap<String, Integer> firstNameCounts = new HashMap<>();
        for (String[] sx : ss) {
            String s = sx[1];
            if (!firstNameCounts.containsKey(s)) {
                firstNameCounts.put(s, 1);
            } else {
                firstNameCounts.put(s, count.get(s) + 1);
            }
        }

        for (int cnt : firstNameCounts.values()) {
            ensure(cnt >= 2, "each first name occurences");
        }

        HashSet<String> patronyms = new HashSet<>();
        for (String[] sx : ss)
            patronyms.add(sx[2]);

        HashSet<String> tmp = new HashSet<String>(lastNames);
        tmp.retainAll(firstNameCounts.keySet());
        ensure(tmp.size() == 0, "last names \\cap first names = \\emptyset");

        tmp = new HashSet<String>(lastNames);
        tmp.retainAll(patronyms);
        ensure(tmp.size() == 0, "last names \\cap patronyms = \\emptyset");

        tmp = new HashSet<String>(firstNameCounts.keySet());
        tmp.retainAll(patronyms);
        ensure(tmp.size() == 0, "first names \\cap patronyms = \\emptyset");

        inf.close();
    }

    public static void main(String[] args) {
        new Validate().run();
    }

    public class StrictScanner {
        private final BufferedReader in;
        private String line = "";
        private int pos;
        private int lineNo;

        public StrictScanner(InputStream source) {
            in = new BufferedReader(new InputStreamReader(source));
            nextLine();
        }

        public void close() {
            ensure(line == null, "Extra data at the end of file");
            try {
                in.close();
            } catch (IOException e) {
                throw new AssertionError("Failed to close with " + e);
            }
        }

        public void nextLine() {
            ensure(line != null, "EOF");
            ensure(pos == line.length(), "Extra characters on line " + lineNo);
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new AssertionError("Failed to read line with " + e);
            }
            pos = 0;
            lineNo++;
        }

        public String next() {
            ensure(line != null, "EOF");
            ensure(line.length() > 0, "Empty line " + lineNo);
            if (pos == 0)
                ensure(line.charAt(0) > ' ', "Line " + lineNo
                        + " starts with whitespace");
            else {
                ensure(pos < line.length(), "Line " + lineNo + " is over");
                ensure(line.charAt(pos) == ' ', "Wrong whitespace on line "
                        + lineNo);
                pos++;
                ensure(pos < line.length(), "Line " + lineNo + " is over");
                ensure(line.charAt(0) > ' ', "Line " + lineNo
                        + " has double whitespace");
            }
            StringBuilder sb = new StringBuilder();
            while (pos < line.length() && line.charAt(pos) > ' ')
                sb.append(line.charAt(pos++));
            return sb.toString();
        }

        public int nextInt() {
            String s = next();
            ensure(s.length() == 1 || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Integer.parseInt(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }

        public long nextLong() {
            String s = next();
            ensure(s.length() == 1 || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Long.parseLong(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }

        public double nextDouble() {
            String s = next();
            ensure(s.length() == 1 || s.startsWith("0.") || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Double.parseDouble(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }
    }

    void ensure(boolean b, String message) {
        if (!b) {
            throw new AssertionError(message);
        }
    }

    void ensureLimits(long n, long from, long to, String name) {
        ensure(from <= n && n <= to, name + " must be from " + from + " to "
                + to);
    }

    void ensureLimits(int n, int from, int to, String name) {
        ensure(from <= n && n <= to, name + " must be from " + from + " to "
                + to);
    }

}
