#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

class Data{
public:
	int w,s;
	string name;
};

int main(){

	int n;
	while(cin>>n&&n!=0){
		Data d[10];
		for(int i = 0; i < n; i++){
			cin>>d[i].name>>d[i].w>>d[i].s;
		}
		vector<int> v;
		for(int i = 0; i < n; i++){
			v.push_back(i);
		}
		double minW=100000000;
		vector<int> p;
		// ツ全ツ津環づィツづ個渉氾板づ計ツ算ツつキツづゥ
		do{
			int sumW=0;
			bool f=true;
			int Bunshi=0;
			for(int i = n-1; i >= 0; i--){
				Bunshi+=(i+1)*d[v[i]].w;
				if(sumW>d[v[i]].s){
					f=false;
					break;
				}
				sumW+=d[v[i]].w;
			}
			// ツづつづ板づェツづ按つ「ツ湘ェツ債、ツ全ツ妥個づ個重ツ心ツづーツ更ツ新ツつキツづゥ
			if(f){
				double G=(double)Bunshi/sumW;
				if(G<minW){
					minW=min(minW,G);
					p=v;
				}
			}
		}while(next_permutation(v.begin(),v.end()));

		for(int i = 0; i < p.size(); i++){
			cout<<d[p[i]].name<<endl;
		}
	//	cout<<endl;
	}

	return 0;
}