
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#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()

struct food{
	string n;
	int w;
	int s;
	int used;
};

int main(void){
	int n;
	while(cin>>n,n){
		vector<food> vf;
		rep(i,n){
			food f;
			cin >> f.n >> f.w >> f.s;
			f.used = 0;
			vf.push_back(f);
		}
		
		int weight = 0 ;
		rep(i,n)weight += vf[i].w;
		rep(i,n){
			vi vec;
			rep(j,n){
				if(!vf[j].used && vf[j].s >= weight - vf[j].w){
					vec.push_back(j);
				}
			}
			int wmax = -1;
			int u;
			rep(j,vec.size()){
				if(wmax < vf[vec[j]].w){
					wmax = vf[vec[j]].w;
					u = vec[j];
				}
			}
			cout<< vf[u].n << endl;
			vf[u].used = 1;
			weight -= vf[u].w;
			
		}
	}

}