#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	string str;
	int n, s, w, sum=0;
	while(cin >> n, n) {
		vector<pair<int, pair<int, string> > > v;
		rep(i,n) {
			cin >> str >> w >> s;
			v.push_back(make_pair(w, make_pair(s, str)));
			sum += w;
		}
		sort(v.begin(), v.end());
		vector<string> ret;
		while(!v.empty()) {
			for(int i = v.size()-1; i>=0; --i) {
				if(sum - v[i].first <= v[i].second.first) {
					ret.push_back(v[i].second.second);
					cout << v[i].second.second << endl;
					sum -= v[i].first;
					v.erase(v.begin() + i);
					break;
				}
			}
		}
	}
    return 0;
}