// 2011/02/06 Tazoe

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

struct food{
	string f;
	int w;
	int s;
};

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		struct food F[10];
		for(int i=0; i<n; i++)
			cin >> F[i].f >> F[i].w >> F[i].s;

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(F[i].w<F[j].w){
					struct food tmp = F[i];
					F[i] = F[j];
					F[j] = tmp;
				}

		for(int i=0; i<n-1; i++){
			int sum = 0;
			for(int j=i+1; j<n; j++)
				sum += F[j].w;

			if(F[i].s>=sum)
				continue;

			int k;
			for(k=i+1; k<n; k++)
				if(F[k].s>=sum+F[i].w-F[k].w)
					break;

			struct food tmp = F[k];
			for(int j=k; j>i; j--)
				F[j] = F[j-1];
			F[i] = tmp;
		}

		for(int i=0; i<n; i++)
			cout << F[i].f << endl;
	}

	return 0;
}