#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int n;
    while(cin >> n, n) {
        vector<tuple<string, int, int>> v(n);
        for(int i=0; i<n; ++i) {
            string name;
            int w, s;
            cin >> name >> w >> s;
            v[i] = make_tuple(name, w, s);
        }
        vector<int> id(n);
        for(int i=0; i<n; ++i) {
            id[i] = i;
        }
        vector<string> res(n);
        double g = 1e9;
        do {
            bool ok = true;
            int sum = 0;
            for(int i=n-1; i>=0; --i) {
                ok &= sum <= get<2>(v[id[i]]);
                sum += get<1>(v[id[i]]);
            }
            if(ok) {
                double g2 = 0;
                for(int i=0; i<n; ++i) {
                    g2 += get<1>(v[id[i]]) * (i+1);
                }
                if(g2 < g) {
                    g = g2;
                    for(int i=0; i<n; ++i) {
                        res[i] = get<0>(v[id[i]]);
                    }
                }
            }
        } while(next_permutation(id.begin(), id.end()));
        
        for(auto& x : res) {
            cout << x << endl;
        }
    }
}
