#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

int n;
double minimum;

using namespace std;

struct Data{
	char name[21];
	int self_weight,bearable_weight,index;
	bool FLG;
};

Data final_data[10];

void recursive(Data data[10],int sum,int index){

	if(index == n){
		double bunshi = 0,bunbo = 0,result;

		for(int i = 1; i <= n-1; i++){
			for(int k = n-1; k >= i; k--){
				if(data[k].index > data[k-1].index)swap(data[k],data[k-1]);
			}
		}


		for(int i = 0; i < n; i++)bunshi += (i+1)*data[i].self_weight;
		for(int i = 0; i < n; i++)bunbo += data[i].self_weight;
		result = bunshi/bunbo;

		if(result < minimum){
			minimum = result;
			for(int k = 0; k < n; k++)final_data[k] = data[k];
		}
		return;
	}

	bool tmpFLG;

	for(int i = 0; i < n; i++){
		if(data[i].FLG == false && data[i].bearable_weight >= sum){
			tmpFLG = true;
			for(int k = 0; k < n; k++){
				if(i != k && data[k].FLG == false && data[k].bearable_weight < sum + data[i].self_weight){
					tmpFLG = false;
					break;
				}
			}

			if(tmpFLG){
				Data new_data[10];
				for(int k = 0; k < n;k++)new_data[k] = data[k];
				new_data[i].FLG = true;
				new_data[i].index = index;
				recursive(new_data,sum+data[i].self_weight,index+1);
			}
		}
	}
}

int main(){

	Data data[10];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		minimum = 2000000000;

		for(int i = 0; i < n; i++){
			data[i].FLG = false;
			scanf("%s %d %d",data[i].name,&data[i].self_weight,&data[i].bearable_weight);
		}

		recursive(data,0,0);

		for(int i = 0; i < n; i++){
			printf("%s\n",final_data[i].name);
		}

	}

    return 0;
}