#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int n;
vi w, s;
vi array;

int best;
vi bestarray;

void solve(int g, int st, int k)
{
	if(g >= best)
		return;
	
	if(k == n){
		best = g;
		bestarray = array;
		return;
	}
	
	reep(i, k, n){
		if(st >= w[array[i]]){
			swap(array[k], array[i]);
			solve(g+(k+1)*w[array[k]], min(st-w[array[k]], s[array[k]]), k+1);
			swap(array[k], array[i]);
		}
	}
}

int main()
{
	while(scanf("%d", &n), n){
		vector<string> f(n);
		w.resize(n);
		s.resize(n);
		rep(i, n){
			char name[32];
			scanf("%s%d%d", name, &w[i], &s[i]);
			f[i] = name;
		}
		
		best = 100000000;
		array.resize(n);
		rep(i, n)
			array[i] = i;
		solve(0, 10000000, 0);
		rep(i, n){
			puts(f[bestarray[i]].c_str());
		}
	}

	return 0;
}