#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

string F[10];
int W[10], S[10];

int main() {
  ios::sync_with_stdio(false);
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    for(int i = 0; i < N; ++i) {
      cin >> F[i] >> W[i] >> S[i];
    }
    vector<int> ord(N);
    for(int i = 0; i < N; ++i) ord[i] = i;
    double ansG = 1e9;
    vector<int> ansOrd;
    do {
      bool ok = true;
      for(int i = 0; i < N; ++i) {
        int w = 0;
        for(int j = i + 1; j < N; ++j) w += W[ord[j]];
        if(w > S[ord[i]]) ok = false;
      }
      if(ok) {
        int g = 0;
        for(int i = 0; i < N; ++i) {
          g += (i + 1) * W[ord[i]];
        }
        double G = 1.0 * g / accumulate(W, W + N, 0);
        if(ansG > G) {
          ansG = G;
          ansOrd = ord;
        }
      }
    } while(next_permutation(ord.begin(), ord.end()));
    for(int item : ansOrd) {
      cout << F[item] << endl;
    }
  }
}