#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

struct food{
  string fn;
  int g;
  int s;
};
int f[10],an[10],m;
food fd[10],sf;
int ans(int n,int s){
  if(n==-1){
    for(int i = m - 1 ; i >= 0 ; i --)
      cout << fd[an[i]].fn << endl; 
      return 1;
  }
 for (i=m-1;i>=0;i--) {
        if (f[i]==0 && fd[i].s>=s-fd[i].g) {
            f[i]=1; an[n]=i;
            if (ans(n-1,s-fd[i].g)==1) return 1; 
            f[i]=0;
        }
  }
  return 0;
}

int main(void){
  int i,j,s;
  while(cin>>m){
    if(m==0)break;
    for(i = 0 , s = 0 ; i < m ; i ++){
      f[i] = 0 ; 
      cin>>fd[i].fn>>fd[i].g>>fd[i].s;
      s+=fd[i].g;
    }
    for(i = 1 ; i < m ; i ++){
      for(j = 0  ; j < m - i ; j ++){
	if(fd[j].g>fd[j+1].g){
	  sf=fd[j];
	  fd[j] = fd[j+1];
	  fd[j+1] = sf;
	}
      }
    }
    ans(m-1,s);
  }
  return 0;
}