#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

bool debug = true;

struct food {
    string name;
    int w, s;
    bool operator<(const food& o) const {
        return w == o.w ? (s == o.s ? name < o.name : s < o.s) : w < o.w;
    }
};

int sum(vector<food> ns) {
    int ret = 0;
    for (int i = 0; i < ns.size(); i++) 
        ret += ns[i].w;
    return ret;
}

bool compare_result(const vector<food>& a, const vector<food>& b) {
    //for (int i = 0; i < a.size(); i++) cout << a[i].w << ' '; cout << endl;
    //for (int i = 0; i < b.size(); i++) cout << b[i].w << ' '; cout << endl;
    for (int i = 0; i < a.size(); i++) {
        if (a[i].w > b[i].w) return true;
        if (a[i].w == b[i].w) continue;
        else return false;
    }
    return true;
}

int n;
int main() {
    while (cin >> n, n != 0) {
        vector<food> foods(n);
        for (int i = 0; i < n; i++) {
            food f;
            cin >> f.name >> f.w >> f.s;
            foods[i] = f;
        }
        sort(foods.begin(), foods.end());
        int total_weight = sum(foods);
        vector<food> res(foods);
        do {
            //for (int i = 0; i < n; i++) cout << foods[i].name << ' '; cout << endl;
            int weight_above = total_weight;
            bool found = true;
            for (int i = 0; i < n; i++) {
                weight_above -= foods[i].w;
//                cout << foods[i].name << ' ' << foods[i].s << ' ' << weight_above << endl;
                if (foods[i].s < weight_above) {
                    found = false;
                    break;
                }
            }
            if (!found) {
                //cout << weight_above << endl;
                continue;
            } else {
                if (compare_result(foods, res)) {
                    res = foods;
                    //for (int i = 0; i < n; i++) cout << res[i].name << ' '; cout << endl;
                }
                //for (int i = 0; i < n; i++) 
                //    cout << foods[i].name << ' '
                //         << foods[i].w    << ' '
                //         << foods[i].s    << ' ' << endl;
                //if (debug) cout << endl;
            }
        } while (next_permutation(foods.begin(), foods.end()));
        for (int i = 0; i < n; i++) 
            //cout << res[i].name << ' '
            //     << res[i].w    << ' '
            //     << res[i].s    << ' ' << endl;
            cout << res[i].name << endl;
        
    }
    return 0;
}