#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

 
const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

ll calc(const vector<pair<int, pll> > &v){
	ll sum = 0LL, ret = 0LL;
	rep(i, v.size()){
		if(v[i].se.se < sum) return LINF;
		sum += v[i].se.fi;
		ret += (v.size() - i) * v[i].se.fi;
	}
	return ret;
}

int main(){
	while(1){
		int n = in.nextInt();
		if(n == 0) break;

		vector<string> s(n);
		vector<int> ans(n);
		ll w = LINF;
		vector<pair<int, pll> > v(n);

		rep(i, n){
			s[i] = in.next();
			v[i].fi = i;
			v[i].se.fi = in.nextLong();
			v[i].se.se = in.nextLong();
		}
		sort(all(v));

		do{
			ll tmp = calc(v);
			if(tmp < w){
				w = tmp;
				rep(i, v.size()) ans[i] = v[i].fi;
			}
		}while(next_permutation(all(v)));

		reverse(all(ans));

		rep(i, n) printf("%s\n", s[ans[i]].c_str());
	}
}