#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

typedef struct Worker {
    int no;
    char name[15];
    int age;
} Worker;

bool cmp(const Worker& a, const Worker& b) {
    if (a.age < b.age) return true;
    else if (a.age == b.age) {
        if (a.no < b.no) return true;
        else if (a.no == b.no) {
            if (a.name == b.name) return true;
        }
    }
    return false;
}

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        Worker w[35];
        for (int i = 0; i < n; i++) scanf("%d%s%d", &w[i].no, w[i].name, &w[i].age);
        sort(w, w + n, cmp);
        n = n > 3 ? 3 : n;
        for (int i = 0; i < n; i++) printf("%d %s %d\n", w[i].no, w[i].name, w[i].age);

    }
    return 0;
}