#include <iostream>
#include <algorithm>

using namespace std;

struct Student{
	string name;
	int age;
	int score;
};
const int MAXN = 1000 + 10;
Student student[MAXN];

bool Compare (Student x, Student y){
	if (x.score != y.score){
		return x.score < y.score;
	}
	if (x.score == y.score && x.name == y.name){
		return x.age < y.age;
	}
	if (x.score == y.score){
		return x.name < y.name; 
	} 
    return false;
}

int main () {
	int n;
	while (cin >> n){
		for (int i = 0; i < n; i++){
			cin >> student[i].name >> student[i].age >> student[i].score;
		}
		sort(student, student + n, Compare);
		for (int i = 0; i < n; i++){
			cout << student[i].name << " " << student[i].age << " " << student[i].score << endl;
		}
	}
	return 0;
}