#include<iostream>
#include<algorithm>
#include<cmath>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define eps (1e-9)
#define equals(a,b) ((fabs((a)-(b))) < eps)
using namespace std;

struct P
{
  string name;
  int w,s,index;
  P(string name="$",int w=inf,int s=inf,int index=-inf):name(name),w(w),s(s),index(index){}
  bool operator < (const P& a)const
  {
    if(w != a.w)return w < a.w;
    if(s != a.s)return s < a.s;
    if(index != a.index)return index < a.index;
    return name < a.name;
  }
};


int main()
{
  int n;
  while(cin >> n,n)
    {
      P info[n];
      string names[n];
      double sum = 0;
      rep(i,n)
	{
	  cin >> info[i].name >> info[i].w >> info[i].s;
	  info[i].index = i;
	  names[i] = info[i].name;
	  sum += info[i].w;
	}
      sort(info,info+n);
      int ans[n],total[n];
      double G = inf;
      do
	{
	  double fac = 0;
	  bool skip = false;
	  rep(i,n)
	    {
	      fac += (i+1)*info[i].w;	  
	      total[i] = info[i].w + (i!=0?total[i-1]:0);
	    }
	  double pG = fac/sum;
	  if(equals(G,pG) || G < pG)continue;
	  
	  rep(i,n)
	    {
	      int on = (int)sum - total[i];
	      if(on > info[i].s)
		{
		  skip = true;
		  break;
		}
	    }       
	  if(skip)continue;


	  G = pG;
	  rep(i,n)ans[i] = info[i].index;

	}while(next_permutation(info,info+n));
      rep(i,n)cout << names[ans[i]] << endl;

    }
  return 0;
}