#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)
#define ll long long
#define P pair<int,int>
#define pb push_back

int n,w[10],s[10],used[10],g;
string F[10];
vector<int> ans;

void f(vector<int> order){
	if(order.size()==n){
		int x=0;
		rep(i,n)x+=w[order[i]]*(n-i);
		if(x<g){
			g=x;
			ans=order;
		}
		return;
	}
	int x=0;
	rep(i,order.size())x+=w[order[i]];
	rep(i,n)if(!used[i]&&s[i]>=x){
		order.pb(i);
		used[i]=1;
		f(order);
		used[i]=0;
		order.pop_back();
	}
}

int main(){
	while(cin>>n&&n){
		fill(used,used+n,0);
		g=INF;
		rep(i,n)cin>>F[i]>>w[i]>>s[i];
		vector<int> v;
		f(v);
		rep(i,n)cout<<F[ans[n-1-i]]<<endl;
	}
}