#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double real;
typedef pair<int, string> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
static inline ll mod_inv(ll a, ll p){ return pow_mod(a,p-2,p); }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
static const int Mod = 1000000000;

static inline int popcnt(int x){ return __builtin_popcount(x); }

struct Food {
  string f;
  int w, s;
  Food(){}
  void read(){
    cin >> f >> w >> s;
  }
  bool operator<(const Food& f) const {
    if (f.s == s) return f.w < w;
    return f.s < s;
  }
};

struct Solver {
  vector<Food> fs;
  vector<Food> best;
  vector<Food> cur;
  bool used[16];
  int best_cg;
  int total_w;
  const int N;

  Solver(int n) : N(n), fs(n) {}
  void init(){
    for (int i = 0; i < N; i++) fs[i].read();
    sort(fs);
    memset(used, 0, sizeof(used));
    best_cg = 1 << 25;
    total_w = 0;
    for (int i = 0; i < N; i++){
      total_w += fs[i].w;
    }
  }
  void solve(int cg=0, int tw=0, int t=1){
    if (t == N + 1){
      if (best_cg > cg){
        best = cur;
        best_cg = cg;
      }
      return;
    }
    if (cg > best_cg) return;
    for (int i = 0; i < N; i++){
      if (used[i]) continue;
      if (fs[i].s < total_w - (tw + fs[i].w)) continue;
      used[i] = true;
      cur.push_back(fs[i]);
      solve(cg + t * fs[i].w, tw + fs[i].w, t + 1);
      cur.pop_back();
      used[i] = false;
    }
  }
  void show(){
    for (int i = 0; i < N; i++) cout << best[i].f << "\n";
  }
};

int main()
{
  int n;
  while (n = in()){
    Solver solver(n);
    solver.init();
    solver.solve();
    solver.show();
  }
  return (0);
}

// priority_queue queue deque first second front top push pop map set stringstream max_element min_element insert count find