#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i> N; std::vectorS(N), id(N); rep(i, N) in >> S[i] >> id[i]; std::vector>book; rep(i, N) { int num; if (id[i] == "iti") num = 1; if (id[i] == "ni") num = 2; if (id[i] == "san") num = 3; if (id[i] == "yon") num = 4; book.push_back(std::make_pair(S[i], num)); } std::sort(book.begin(), book.end()); rep(i, N) { std::string str; if (book[i].second == 1) str = "iti"; if (book[i].second == 2) str = "ni"; if (book[i].second == 3) str = "san"; if (book[i].second == 4) str = "yon"; out << book[i].first << " " << str << std::endl; } }