#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

		vector<int> opt(n);
		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;
				opt=perm;
			}
		}while(next_permutation(perm.begin(),perm.end()));

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

	return 0;
}