#include #include #include #include #include #include typedef int32_t i32; typedef int64_t i64; #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) typedef struct node { char *s; i32 index; } node; int cmp (const void *a, const void *b) { const node *p = a; const node *q = b; int c = strcmp(p->s,q->s); if (c != 0) return c; return p->index - q->index; } void run (void) { i32 n; scanf ("%" SCNi32, &n); char *s = (char *) calloc (26 * n, sizeof (char)); node *p = (node *) calloc (n, sizeof (node)); for (i32 i = 0; i < n; ++i) { scanf ("%s", s + 26 * i); char t[10]; scanf ("%s", t); p[i] = (node) {s + 26 * i, t[0] == 'i' ? 0 : t[0] == 'n' ? 1 : t[0] == 's' ? 2 : 3}; } qsort (p, n, sizeof (node), cmp); char *ans[4] = {"iti","ni","san","yon"}; for (i32 i = 0; i < n; ++i) { printf ("%s %s\n", p[i].s,ans[p[i].index]); } } int main (void) { run (); return 0; }