#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< VI > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;

template < typename T > inline void input_n( vector< T > &out ) { copy_n( istream_iterator< T >( cin ), out.size(), out.begin() ); };
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) (c).begin(), (c).end()
#define AALL( a, t ) (t*)a, (t*)a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define EM( n ) emplace( n )
#define EB( n ) emplace_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

struct Food
{
	int id;
	string name;
	double w, s;

	Food( const int id, const string &name, const int w, const int s ) :
		id( id ), name( name ), w( w ), s( s )
	{
		return;
	}

	bool operator<( const Food &rhs ) const
	{
		return id < rhs.id;
	}
};

double center( const vector< Food > &foods )
{
	const int N = foods.size();

	for ( int i = N - 1, sum = 0; 0 <= i; sum += foods[ i-- ].w )
	{
		if ( foods[i].s < sum )
		{
			return numeric_limits< double >::max();
		}
	}

	double g = 0, ss = 0;
	REP( i, 0, N )
	{
		g += ( i + 1 ) * foods[i].w;
		ss += foods[i].w;
	}

	return g / ss;
}


int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	for ( int n; cin >> n, n; )
	{
		vector< Food > foods;

		REP( i, 0, n )
		{
			string f;
			int w, s;
			cin >> f >> w >> s;

			foods.emplace_back( i, f, w, s );
		}

		double ming = numeric_limits<double>::max();
		vector< Food > res;

		do
		{
			const double g = center( foods );
			if ( g < ming )
			{
				res = foods;
				ming = g;
			}
		}
		while ( next_permutation( ALL( foods ) ) );

		FOR( r, res )
		{
			cout << r.name << endl;
		}
	}

	return 0;
}