#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Food{
	string f;
	int w,s;
	bool operator <(const Food &a)const{
		if(w==a.w) return s>a.s;
		return w>a.w;
	}
};

int main(){
	int N;
	while(cin>>N,N){
		int sumW = 0;
		Food food[10];
		for(int i=0;i<N;i++){
			cin>>food[i].f>>food[i].w>>food[i].s;
			sumW += food[i].w;
		}
		sort(food,food+N);
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(food[j].w == -1) continue;
				if(food[j].s >= sumW-food[j].w){
					cout<<food[j].f<<endl;
					sumW -= food[j].w; food[j].w = -1; break;
				}
			}
		}
		
	}
	return 0;
}