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

struct Food{
  string name;
  int weight, durability;
};

int n, minG;
Food bag[11];
int order[11], bestOrder[11];
bool used[11];

void dfs(int selectedNum, int totalWeight, int numerG){
  if(selectedNum != 0 && numerG > minG) return;

  if(selectedNum == n){
    if(numerG < minG){
      minG = numerG;
      for(int i = 1; i <= n; i++) bestOrder[i] = order[i];
    }
    return;
  }

  for(int i = 1; i <= n; i++){
    if(!used[i] && bag[i].durability >= totalWeight){
      used[i] = true;
      order[selectedNum + 1] = i;
      dfs(selectedNum + 1, totalWeight + bag[i].weight, numerG + (n - selectedNum) * bag[i].weight);
      used[i] = false;
    }
  }
}

int main(void){
  while(cin >> n && n != 0){
    minG = INT_MAX;
    for(int i = 1; i <= n; i++){
      cin >> bag[i].name >> bag[i].weight >> bag[i].durability;
      used[i] = false;
    }
    dfs(0, 0, 0);
    for(int i = n; i >= 1; i--) cout << bag[bestOrder[i]].name << endl;
  }
  return 0;
}