#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    while(1){
        int n, w[15], s[15], mi=IINF;
        string f[15];
        vector<int> v, ans;
        cin >> n;
        if(n==0)break;
        REP(i,n){
            cin >> f[i] >> w[i] >> s[i];
            v.push_back(i);
        }
        while(1){
            int cum[15]{}, tmp=0;
            REP(i,n) cum[i+1] += cum[i] + w[v[i]];
            bool ok = true;
            REP(i,n) ok &= s[v[i]] >= cum[n]-cum[i+1];
            if(ok){
                REP(i,n){
                    tmp += w[v[i]]*(i+1);
                }
                if(tmp < mi){
                    mi = tmp;
                    ans = v;
                }
            }
            if(!next_permutation(ALL(v)))break;
        }
        for(auto i : ans){
            cout << f[i] << endl;
        }
    }
    return 0;
}   

