#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¼

vector <ITEM> list;
int N;
vector <vector <int> > order;

int calcG (map <int, int> item )
{
	int res = 0;

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

	return res;
}

void dfs (vector <int> & used, int depth )
{
	if (depth >= N ){
		order.push_back(used );
		return;
	} // end if

	for (int i = 0; i < N; ++i ){
		if (used[i] == -1 ){
			used[i] = depth;
			int sum = 0;
			for (int j = 0; j < N; ++j ){
				if (j != i && used[j] == -1 ){	 
					sum += list[j].first.first;
				} // end if
			} // end for
			if (sum <= list[i].first.second ){
				dfs (used, depth + 1 );
			} // end if
			used[i] = -1;
		} // end if
	} // end for
}

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

	while (cin >> n && n ){
		N = n;
		order.clear();
		list.clear();
		list.resize(n);
		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> used (n, -1 );

		dfs (used, 0 );

		multimap <int, map <int, int> > rank;
		for (int i = 0; i < order.size(); ++i ){
			map <int, int> packed;
			for (int j = 0; j < order[i].size(); ++j ){
				packed[order[i][j]] = j;
			} // end for
			double G = calcG (packed );
			rank.insert (make_pair (G, packed ) );
		} // end for

		multimap <int, map<int, int> >::iterator it = rank.begin();
		map <int, int> res = (*it).second;
		map <int, int>::iterator jt = res.begin();

		for (; jt != res.end(); ++jt ){
			cout << list[(*jt).second].second << endl;
		} // end for

	} // end while

		
	return 0;
}