#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    vector<int> ans(n), per(n), w(n), s(n);
    vector<string> name(n);
    int g = INT_MAX;
    REP(i,n){
      cin>>name[i]>>w[i]>>s[i];
      per[i] = i;
    }
    do{
      int gg = 0;
      int ww = 0;
      bool flag = true;
      for(int i=n-1; i>=0; i--){
	int pp = per[i];
	if(s[pp] < ww){
	  flag = false;
	  break;
	}
	ww += w[pp];
	gg += (i+1) * w[pp];
      }
      if(flag && g > gg){
	g = gg;
	ans = per;
      }
    }while(next_permutation(per.begin(), per.end()));
    
    REP(i,n) cout << name[ans[i]] << endl;
  }
  return 0;
}