#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair; vector ids = {"iti", "ni", "san", "yon"}; int main() { int n; cin >> n; vector> p(n); rep(i, n) { string s; string id; cin >> s >> id; rep(j, 4) if (id == ids[j]) { p[i] = make_pair(s, j); break; } } sort(p.begin(), p.end()); rep(i, n) { cout << p[i].first << " " << ids[p[i].second] << endl; } return 0; }