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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin >> n, n){

        vector<int> p(n);
        rep(i, n){
            p[i] = i;
        }

        vector<string> f(n);
        vector<lint> w(n), s(n);
        rep(i, n){
            cin >> f[i] >> w[i] >> s[i];
        }

        vector<int> ans;
        lint mini = 1000000000000LL;

        do{

            bool flag = true;
            lint g = 0, cnt = 0;

            rep(i, n){
                flag &= cnt <= s[p[i]];
                cnt += w[p[i]];
                g += (lint)(n - i) * w[p[i]];
            }

            if(flag && mini > g){
                ans = p;
                mini = g;
            }

        }while(next_permutation(p.begin(), p.end()));

        repr(i, n){
            cout << f[ans[i]] << endl;
        }

    }

    return 0;
}
