#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef pair <string, II> NODE;
typedef vector <NODE> NODES;

void solve( int n, NODES nodes ) {
    int ming = INT_MAX;
    VS L;
    VI ID(n);
    for ( int i = 0; i < n; ++ i ) {
        ID[i] = i;
    }
    do {
        int wsum = 0, g = 0;
        for ( int i = 0; i < n; ++ i ) {
            if ( wsum > nodes[ID[i]].second.second ) goto out_1;
            wsum += nodes[ID[i]].second.first;
        }
        for ( int i = 0; i < n; ++ i ) {
            g += ( n - i ) * nodes[ID[i]].second.first;
            if ( g >= ming ) goto out_1;
        }
        if ( g < ming ) {
            ming = g;
            VS T;
            for ( int i = 0; i < n; ++ i ) {
                T.push_back( nodes[ID[i]].first );
            }
            L = T;
        }
    out_1:;
    } while ( next_permutation( ID.begin(), ID.end() ) );

    reverse( L.begin(), L.end() );
    for ( int i = 0; i < n; ++ i ) {
        cout << L[i] << endl;
    }
}

int main() {
    int n;
    while ( cin >> n && n ) {
        NODES nodes( n );
        for ( int i = 0; i < n; ++ i ) {
            cin >> nodes[i].first >> nodes[i].second.first >> nodes[i].second.second;
        }
        solve( n, nodes );
    }
    return 0;
}