Go: package main

import (
	"bufio"
		"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
var f = make([]string, 10)
var s, w = make([]int, 10), make([]int, 10)
var n int
func main() {
	for scanner.Scan() {
		n, _ = strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			tmpf :=buf[0]
			tmpw, _ := strconv.Atoi(buf[1])
			tmps, _ := strconv.Atoi(buf[2])
			f[i] = tmpf
			s[i] = tmps
			w[i] = tmpw
		}
		sort()
		for i := 0; i < n; i++ {
			for j := 0; j < n-1; j++ {
				if w[j]<w[j+1] {
					swap(j)
					a := get_weight(j+1)
					if a>s[j] {
						swap(j)
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			fmt.Println(f[i])
		}
	}
}

func sort() {
	for i := n-1; i > 0; i-- {
		for j := 0; j < i; j++ {
			if s[j]<s[j+1] {
				swap(j)
			} else if s[j]==s[j+1]&&w[j]<w[j+1] {
				swap(j)
			}
		}
	}
}

func swap(x int) {
	w[x], w[x+1] = w[x+1], w[x]
	s[x], s[x+1] = s[x+1], s[x]
	f[x], f[x+1] = f[x+1], f[x]
}

func get_weight(x int) int {
	ret := 0
	for i := x; i < n; i++ {
		ret += w[i]
	}
	return ret
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

int main(){
	int n;
	vector<pair<string,pii> > data;
	vector<pair<string,pii> > ans;
	while(scanf("%d",&n)){
		if(n==0)break;
		data.clear();
		ans.clear();
		string str;
		int w,s;
		int tmp2 =0;
		for(int i =0;i <n;i++){
			cin>>str;
			scanf("%d %d",&w,&s);
			data.push_back(mp(str,pii(w,s)));
			tmp2 +=data[i].second.first;
		}
		sort(data.begin(),data.end());
		double G =1145141;
		do{
			//cout <<"iei"<<endl;
			int sumw =0;
			int tmp1 =0;
			for(int i =n-1;i >=0;i--){
				tmp1 +=(i+1)*data[i].second.first;
			}
			double Gtmp =(double)((double)tmp1/(double)tmp2);
			if(Gtmp>G)continue;
			bool ok =true;
			for(int i =n-1;i >=0;i--){
				if(sumw>data[i].second.second){
					ok =false;
					break;
				}else{
					sumw +=data[i].second.first;
				}
			}
			//cout <<Gtmp<<endl;
			if(ok&&Gtmp <G){
				G =Gtmp;
				ans=data;
				//cout <<"ge"<<endl;
			}
		}while(next_permutation(data.begin(), data.end()));

		for(int i =0;i <n;i++){
			printf("%s\n",ans[i].first.c_str());
		}
	}
	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int n;
	string s;
	int a, b;
	while (cin >> n&&n) {
		vector<pair<int, string>>v;
		for (int i = 0; i < n; i++) {
			cin >> s >> a >> b;
			v.emplace_back(make_pair(b, s));
		}
		sort(v.begin(), v.end());
		for (int i = n-1; i >= 0; i--) {
			cout << v[i].second << endl;
		}
	}
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int n;
vi w, s;
int array[10];

int best;
int bestarray[10];

void solve(int g, int st, int k)
{
	if(g >= best)
		return;
	
	if(k == n){
		best = g;
		copy(array, array+n, bestarray);
		return;
	}
	
	reep(i, k, n){
		if(st >= w[array[i]]){
			swap(array[k], array[i]);
			solve(g+(k+1)*w[array[k]], min(st-w[array[k]], s[array[k]]), k+1);
			swap(array[k], array[i]);
		}
	}
}

int main()
{
	while(scanf("%d", &n), n){
		vector<string> f(n);
		w.resize(n);
		s.resize(n);
		rep(i, n){
			char name[32];
			scanf("%s%d%d", name, &w[i], &s[i]);
			f[i] = name;
		}
		
		best = 100000000;
		rep(i, n)
			array[i] = i;
		solve(0, 10000000, 0);
		rep(i, n){
			puts(f[bestarray[i]].c_str());
		}
	}

	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

double getcog(vi& ps,vi& ws)
{
	int size=ps.size();
	int temp=0;
	rep(i,size)
		temp+=(i+1)*ws[ps[i]];
	return (double)temp/accumulate(allof(ws),0);
}

int main()
{
	for(int n;cin>>n,n;){
		vs ns(n);
		vi ws(n),cs(n);
		rep(i,n)
			cin>>ns[i]>>ws[i]>>cs[i];
		
		double cog=1e10;
		vi ps(n),res(n);
		vi ss(n);
		rep(i,n) ps[i]=i;
		do{
			for(int i=n-2;i>=0;i--)
				ss[i]=ss[i+1]+ws[ps[i+1]];
			bool ok=true;
			rep(i,n)
				ok&=ss[i]<=cs[ps[i]];
			if(ok){
				double temp=getcog(ps,ws);
				if(temp<cog){
					cog=temp;
					res=ps;
				}
			}
		}while(next_permutation(allof(ps)));
		
		rep(i,n)
			cout<<ns[res[i]]<<endl;
	}
	
	return 0;
}