#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

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

bool isValid(int id[]) {
  int sumW = 0;
  for(int i = N-1; i >= 0; --i) {
    if(S[id[i]] < sumW) return false;
    sumW += W[id[i]];
  }
  return true;
}

double getG(int id[]) {
  int a, b;
  a = b = 0;
  for(int i = 0; i < N; ++i) {
    a += W[id[i]]*(i+1);
    b += W[id[i]];
  }
  return (double)a/b;
}

void solve() {
  int id[N], ans[N];
  double g = -1;
  for(int i = 0; i < N; ++i) id[i] = i;
  do {
    if(isValid(id)) {
      double newG = getG(id);
      if(g == -1 || newG < g) {
	g = newG;
	for(int i = 0; i < N; ++i) ans[i] = id[i];
      }
    }
  } while(next_permutation(id, id+N));
  for(int i = 0; i < N; ++i) cout << F[ans[i]] << endl;
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i)
      cin >> F[i] >> W[i] >> S[i];
    solve();
  }
  return 0;
}