#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require sqrt ceil floor
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <stdint.h>	// require uint64_t
#include <fstream>	// require freopen

using namespace std;

typedef pair <pair<int, int>, string > ITEM;	// ACeÌd³AACeÌãÉu¯éd³ÌãÀAACe¼

int memo[10][10];		// s: ACe¼ ñ:½iÚ© -1: Ü¾ãÉÏßé©Ç¤©¢èA0:ÏßÈ¢ 1: Ïßé
vector <ITEM> list;
int N;
int minG;
vector <int> minorder;
int total;

int getG (vector <int> order )
{
	int res = 0;

	for (int i = 0; i < order.size(); ++i ){
		res += (i+1)*(list[order[i]].first.first);
	} // end for

	return res;
}

void bt (vector <int> & order, int curr )
{
	if (curr == N ){
		int currG = getG (order );
		if (currG < minG ){
			minorder = order;
			minG = currG;
		} // end if
		return;
	} // end if

	if (order[curr] != -1 && memo[order[curr]][curr] == 0 ){
		return;
	} // end if

	if (order[curr] == -1 ){
		vector <bool> used (N, false );
		for (int i = 0; i < curr; ++i ){
			used[order[i]] = true;
		} // end if

		for (int i = 0; i < N; ++i ){
			if (!used[i] ) {
				order[curr] = i;
				int curr_w = total;
				for (int j = 0; j <= curr; ++j ){
					curr_w -= list[order[j]].first.first;
				} // end for
				if (curr_w <= list[order[curr]].first.second ){
					memo[order[curr]][curr] = 1;
					bt (order, curr + 1 );
				}else{
					memo[order[curr]][curr] = 0;
				}// end if
				order[curr] = -1;
			} // end if
		} // end for
	} // end if

}

void init (int n )
{
	N = n;
	list.clear();
	list.resize(n);
	minorder.clear();
	minorder.resize(n);
	total = 0;
	minG = INT_MAX;
	memset (memo, -1, sizeof(memo) );
}	

int main()
{
//	cut here before submit 
//	freopen ("testcase.lunch", "r", stdin );
	int n;

	while (cin >> n && n ){
		init (n );
		for (int i = 0; i < n; ++i){
			cin >> list[i].second;
			cin >> list[i].first.first;	// w
			cin >> list[i].first.second;	// s
			total += list[i].first.first; 
		} // end for
		vector <int> order(n, -1 );

		bt (order, 0 );

		for (int i = 0; i < n; ++i ){
			cout << list[minorder[i]].second << endl;
		} // end for

	} // end loop
		
	return 0;
}