import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class BookShelf { final static String ONE = "iti"; final static String TWO = "ni"; final static String THREE = "san"; final static String FOUR = "yon"; static int o1Num = 0; static int o2Num = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[][] s = new String[n][2]; // 入力を配列に for (int i = 0; i < n; i++) { String[] a = { sc.next(), sc.next() }; s[i] = a; } // 巻数順に並べる Arrays.sort(s, new Comparator() { public int compare(String[] o1, String[] o2) { o1Num = Num(o1[1]); o2Num = Num(o2[1]); return o1Num - o2Num; } }); // 本のタイトルをソート Arrays.sort(s, new Comparator() { public int compare(String[] a, String[] b) { return (a[0].compareTo(b[0])); } }); // 出力 for (String[] b : s) { System.out.println(b[0] + " " + b[1]); } sc.close(); } // 文字列の巻数を数字で扱う static int Num(String strNum) { switch (strNum) { case ONE: return 1; case TWO: return 2; case THREE: return 3; case FOUR: return 4; default: return 0; } } }