#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T> bool chmin(T &a, const T &b){ return a > b && (a = b, true);}
template<class T> bool chmax(T &a, const T &b){ return a < b && (a = b, true);}

int main() {
    int n;
    while(cin >> n, n){
        vector<string> S(n);
        vector<int> W(n), A(n);
        for (int i = 0; i < n; ++i) {
            cin >> S[i] >> W[i] >> A[i];
        }
        vector<int> T(1 << n), cnt(1 << n);
        for (int i = 0; i < (1 << n); ++i) {
            for (int j = 0; j < n; ++j) {
                if(i&(1 << j)) {
                    T[i] = T[i^(1 << j)]+W[j];
                    cnt[i] = cnt[i^(1 << j)]+1;
                }
            }
        }
        vector<int> dp(1 << n, INF<int>), top(1 << n, INF<int>);
        dp[0] = 0;
        for (int i = 0; i < (1 << n); ++i) {
            for (int j = 0; j < n; ++j) {
                if(!(i & (1 << j)) && A[j] >= T[i]){
                    if(chmin(dp[i^(1 << j)], dp[i]+(n+1-cnt[i])*W[j])){
                        top[i^(1 << j)] = j;
                    }
                }
            }
        }
        int cur = (1 << n)-1;
        queue<string> ans;
        while(cur){
            ans.emplace(S[top[cur]]);
            cur -= 1 << top[cur];
        }
        while(!ans.empty()){
            cout << ans.front() << "\n"; ans.pop();
        }
    }
    return 0;
}
