#include <stdio.h>
#include <stdlib.h>
struct friends {
char name[11];
int birth;
char tele[18];
} friend[9];
int cmp(const void *a, const void *b) {
return ((struct friends *)a)->birth > ((struct friends *)b)->birth;
}
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
getchar();
scanf("%s%d%s", friend[i].name, &friend[i].birth, friend[i].tele);
}
qsort(friend, n, sizeof(struct friends), cmp);
for (i = 0; i < n; i++) printf("%s %d %s\n", friend[i].name, friend[i].birth, friend[i].tele);
return 0;
}