#include using namespace std; int main() { int n; cin >> n; vector> ss; for (int i = 0; i < n; i++) { string a, b; cin >> a >> b; if (b == "iti") { b = "1iti"; } else if (b == "ni") { b = "2ni"; } else if (b == "san") { b = "3san"; } else { b = "4yon"; } ss.emplace_back(a, b); } sort(ss.begin(), ss.end()); for (int i = 0; i < n; i++) { cout << ss[i].first << ' ' << ss[i].second.substr(1) << '\n'; } }