#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

struct data{
    string name;
    int w, s;
};

bool cmp(data d1, data d2){
    if(d1.w == d2.w){
        return d1.s > d2.s;
    }
    return d1.w > d2.w;
};

signed main(){
    int n;
    while(cin >> n, n){
        vector<data> in(n);
        int sum = 0;
        rep(i, 0, n){
            cin >> in[i].name >> in[i].w >> in[i].s;
            sum += in[i].w;
        }
        vector<string> ans;
        rep(i, 0, n){
            sort(all(in), cmp);
            rep(j, 0, in.size()){
                if(in[j].s >= sum - in[j].w){
                    ans. push_back(in[j].name);
                    sum -= in[j].w;
                    in[j].w = -1;
                    in[j].s = -1;
                }
            }
        }
        rep(i, 0, n){
            cout << ans[i] << endl;
        }
    }
}