#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

struct Entry {
	Entry(){ }
	Entry(const Entry &obj) : name(obj.name), w(obj.w), s(obj.s) { }
	Entry &operator=(const Entry &obj){ name = obj.name; w = obj.w; s = obj.s; return *this; }
	string name;
	int w, s;
};

struct WeightComparator {
	bool operator()(const Entry &a, const Entry &b){ return a.w < b.w; }
};

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<Entry> entries;
		int wsum = 0;
		while(n--){
			Entry e;
			cin >> e.name >> e.w >> e.s;
			wsum += e.w;
			entries.push_back(e);
		}
		priority_queue<Entry, vector<Entry>, WeightComparator> q;
		while(!entries.empty() || !q.empty()){
			vector<Entry>::iterator it = entries.begin();
			while(it != entries.end()){
				if((*it).s >= wsum - (*it).w){
					q.push(*it);
					it = entries.erase(it);
				}else{
					++it;
				}
			}
			wsum -= q.top().w;
			cout << q.top().name << endl;
			q.pop();
		}
	}
	return 0;
}