#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	char name[30][21];
	int wei[30],safe[30],perm[30];
	for(int n;scanf("%d",&n),n;){
		for(int i=0;i<n;i++){
			scanf("%s%d%d",name[i],&wei[i],&safe[i]);
			perm[i]=i;
		}

		int opt[30];
		double gopt=-1;
		do{
			bool b=true;

			int wsum=0,g=0;
			for(int i=0;i<n;i++){
				int now=perm[i];
				if(wsum>safe[now]){
					b=false;
					break;
				}
				wsum+=wei[now];
				g+=(i+1)*wei[now];
			}

			if(!b)	continue;

			if(gopt<(double)g/wsum){
				gopt=(double)g/wsum;
				for(int i=0;i<n;i++)	opt[i]=perm[i];
			}
		}while(next_permutation(perm,perm+n));

		for(int i=n-1;i>=0;i--)	puts(name[opt[i]]);
	}

	return 0;
}