#include<vector>
#include<map>
#include<string>
#include<algorithm>
#define repb(i,n) for(int i=n;i--;)
using namespace std;
int main(){
	int n,s,w,W; string f;
	while(cin>>n,n){
		vector<pair<int,pair<int, string> > > t; W=0;
		repb(i,n){
			cin>>f>>w>>s;
			t.push_back(make_pair(w,make_pair(s,f)));
			W+=w;
		}
		sort(t.begin(),t.end());
		vector<string> fukuro;
		while(!t.empty()){
			repb(i,t.size())if(W-t[i].first<=t[i].second.first){
				fukuro.push_back(t[i].second.second);cout<<t[i].second.second<<endl;
				W-=t[i].first;
				t.erase(t.begin()+i);
				break;
			}
		}
	}
	return 0;
}