#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<string> f(n);
    vector<int> w(n), s(n), ord(n);
    for (int i = 0; i < n; i++) {
      cin >> f[i] >> w[i] >> s[i];
      ord[i] = i;
    }
    double G = 1e9;
    vector<int> ans(n);
    do {
      int sum = 0, no = 0;
      for (int i = n - 1; i >= 0; i--) {
        if (s[ord[i]] < sum) no++;
        sum += w[ord[i]];
      }
      if (no) continue;
      int tmp = 0;
      for (int i = 0; i < n; i++) {
        tmp += (i + 1) * w[ord[i]];
      }
      double g = 1. * tmp / sum;
      if (G - g > 1e-10) {
        G = g;
        ans = ord;
      }
    } while (next_permutation(ord.begin(), ord.end()));
    for (int i = 0; i < n; i++) {
      cout << f[ans[i]] << endl;
    }
  }

  return 0;
}
