#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 dfs (vector <int> order, int curr )
{
	if (curr == N ){
		return 1;
	} // end if

	if (memo[order[curr]][curr] == 0 ){
		return 0;
	} // end if
		
	int total_wight = 0;

	for (int i = curr + 1; i < N; ++i ){
		total_wight += list[order[i]].first.first;
	} // end if

	if (total_wight <= list[order[curr]].first.second ){
		memo[order[curr]][curr] = 1;
		return dfs (order, curr + 1 );
	}else{
		return (memo[order[curr]][curr] = 0);
	} // end if

	return 0;
}

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;
}

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

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

		vector <int> minorder;
		int minG = INT_MAX;
		do{
			if (dfs (order, 0) > 0){
				int currG = getG (order );
				if (currG < minG ){
					minorder = order;
					minG = currG;
				} // end if
			} // end if
		}while (next_permutation (order.begin(), order.end() ) );

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

	} // end loop
		
	return 0;
}