#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
#include<sstream>
using namespace std;
#define all(a) a.begin(),a.end()
typedef vector<int> vi;
struct food
{
	string name;
	int w,s;
};
typedef vector<food> vf;
int n;
int main()
{
	while(cin>>n&&n)
	{
		vf a;
		vi ans,s;
		for(int i=0;i<n;i++)
		{
			food f;
			s.push_back(i);
			cin>>f.name>>f.w>>f.s;
			a.push_back(f);
		}
		double t=9999999999999;
		do
		{
			vi sum;
			double r=0,f=0;
			for(int i=0;i<n;i++)
			{
				sum.push_back(a[s[i]].w);
				r+=(i+1)*a[s[i]].w;
				f+=a[s[i]].w;
			}
			for(int i=n-1;i>0;i--)sum[i-1]+=sum[i];
			sum.push_back(0);
			bool ok=true;
			for(int i=0;i<n;i++){if(sum[i+1]>a[s[i]].s)ok=false;}
			if(!ok)continue;
			if(t>r/f)
			{
				t=r/f;
				ans=s;
			}
		}while(next_permutation(all(s)));
		for(int i=0;i<n;i++)
		{
			cout<<a[ans[i]].name<<endl;	
		}
		
	}
}