#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<climits>
#include<cmath>
#include<stdio.h>
using namespace std;

struct food{
    string name;
    int weight;
    int ue;
    int id;
};
struct com
{
    inline bool operator() (const food& f1, const food& f2){
        return (f1.id > f2.id);
    }
};
int main(){
    int n;
    while(cin>>n,n){
        vector<food>vec,v;
        int totWeight=0;
        for(int i=0;i<n;i++){
            food f;
            cin>>f.name>>f.weight>>f.ue;
            f.id=i;
            totWeight += f.weight;
            vec.push_back(f);
            v.push_back(f);
        }
        sort(vec.begin(),vec.end(),com());
        vector<pair<double,vector<int> > >ve;
        do{
            bool ok=true;
            int tot=0;
            for(int i=n-1;i>=0;i--){
                if(tot>vec[i].ue){
                    ok=false;
                    break;
                }
                tot+=vec[i].weight;
            }
            if(ok){
                double x=0;
                for(int i=0;i<n;i++){
                    x+=(n-i)*vec[i].weight;
                }
                x/=totWeight;
                vector<int>ids;
                for(int i=0;i<n;i++){
                    ids.push_back(vec[i].id);
                }
                ve.push_back(make_pair(x, ids));
            }
        } while(next_permutation(vec.begin(), vec.end(), com()));
        sort(ve.begin(),ve.end());
        for(int i=0;i<n;i++){
            cout<<v[ve[ve.size()-1].second[i]].name<<endl;
        }
    }
    return 0;
}