#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct A
{
string name;
int b,c;
}a[200010];
bool cmp( A &x,A &y)
{
if( x.b != y.b ) return x.b > y.b;
if( x.c != y.c ) return x.c < y.c;
return x.name > y.name;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for( int i = 0; i < n; i++ ) cin >> a[i].name >> a[i].b >> a[i].c;
sort( a, a + n, cmp );
for( int i = 0; i < n; i++ ) cout << a[i].name << endl;
return 0;
}