#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<pair<int,int>,string> item;
int main(){
	int n,i,w,s,S;
	string f;
	for(;cin>>n,n;){
		vector<item> items,result;
		for(i=0;i<n;i++)cin>>f>>w>>s,items.push_back(make_pair(make_pair(w,s),f));
		sort(items.begin(),items.end());
		S=99999;
		do{
			for(s=w=i=0;i<n;i++){
				if(items[i].first.second<w)break;
				w+=items[i].first.first;
				s+=(n-i)*items[i].first.first;
			}
			if(i==n&&s<S)S=s,result=items;
		}while(next_permutation(items.begin(),items.end()));
		reverse(result.begin(),result.end());
		for(i=0;i<n;i++)cout<<result[i].second<<endl;
	}
}