#include<iostream>
#include<string>
using namespace std;

string f[11];
int ans[11];
int n;
int w[11],s[11];

void solve(){
	for(int i=1; i<=n; i++)
		ans[i] = i;
	for(int k=1; k<=n; k++){
		for(int i=n; i>k; i--){
			if(s[i] > s[i-1]){
				int tmp = s[i];
				s[i] = s[i-1];
				s[i-1] = tmp;
				tmp = ans[i];
				ans[i] = ans[i-1];
				ans[i-1] = tmp;
			}
		}
	}
}

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		for(int i=1; i<=n; i++)
			cin >> f[i] >> w[i] >> s[i];
		solve();
		for(int i=1; i<=n; i++)
			cout << f[ans[i]] << endl;
	}
}