#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

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

        vector<int> p(n);//配列のインデックス
        vector<string> f(n);
        vector<int> w(n),s(n),ans(n);
        int mini = INF;

        for(int i = 0;i < n;i++){
            p[i] = i;
        }

        for(int i = 0;i < n;i++){
            cin >> f[i] >> w[i] >> s[i];
        }

        do{

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

            for(int i = 0;i < n;i++){

                flag &= (cnt <= s[p[i]]);//上から見る
                cnt += w[p[i]];
                g += (n-i)*w[p[i]];
            }

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

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

        for(int i = n-1;i >= 0;i--){
            cout << f[ans[i]] << endl;
        }
    }


    return 0;
}
