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++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

struct FOOD{
	string name;
	int w;
	int s;
};

struct DATA{
	double G;
	vector<FOOD> mFoods;
};

struct DATA dp[1<<10][10];

bool checkWeight(const vector<FOOD>& vf){
	for(int i=0;i<vf.size();i++){
		int sum = 0;
		for(int j=i+1;j<vf.size();j++){
			sum += vf[j].w;
		}
		if(vf[i].s < sum) return false;
	}

	return true;
}

double getG(const vector<FOOD>& vf){

	double G=0;
	double sum=0;
	for(int i=0;i<vf.size();i++){
		G += vf[i].w * (i+1);
		sum += vf[i].w;
	}
	return G / sum;
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;

		struct FOOD* food = new struct FOOD[n];

		for(int i=0;i<n;i++){
			char buf[64];
			int w,s;
			scanf("%s %d %d",buf,&w,&s);
			food[i].name = buf;
			food[i].s = s;
			food[i].w = w;
		}

		int* table = new int[n];
		for(int i=0;i<n;i++) table[i] = i;

		vector<FOOD> Foods;

		struct DATA res;
		res.G = 1000000;
		do{
			for(int i=0;i<n;i++){
				Foods.push_back(food[table[i]]);
			}

			double tmpG;
			if(checkWeight(Foods) &&
				res.G > (tmpG = getG(Foods))){
					res.mFoods = Foods;
					res.G = tmpG;
			}
			Foods.clear();
		}while(next_permutation(table,table+n));

		for(int i=0;i<res.mFoods.size();i++){
			printf("%s\n",res.mFoods[i].name.c_str());
		}

		delete[] food;
		delete[] table;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, w[1000], s[1000];
string S[1000]; vector<int>b; int maxn;
int main() {
	while (true) {
		cin >> n; b.clear(); maxn = 1 << 30;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> S[i] >> w[i] >> s[i];
		}
		vector<int>a(n, 0);
		for (int i = 0; i < n; i++)a[i] = i;
		do {
			int sum2 = 0;
			for (int i = 0; i < n; i++) {
				int sum = 0;
				for (int j = i + 1; j < n; j++) {
					sum += w[a[j]];
				}
				if (sum > s[a[i]]) goto E;
			}
			for (int i = 0; i < n; i++) {
				sum2 += i*w[a[i]]; maxn = sum2;
			}
			if (maxn > sum2)b = a;
		E:;
		} while (next_permutation(a.begin(), a.end()));
		for (int i = 0; i < n; i++) { cout << S[b[i]] << endl; }
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e9;
typedef vector<int> iv;

double G;
int N;
vector<int> u;

bool check(int n, iv &used, iv &w, iv &s){
  int sum = 0;
  REP(i, N) if(used[i] != -1) sum += w[i];
  return sum <= s[n];
}

void dfs(int sum, int cnt, iv &used, iv &w, iv &s, vector<string> &f){
  if(cnt <= 0){
    double a = 0, b = 0;
    REP(i, N){
      a += used[i] * w[i];
      b += w[i];
    }
    if(a / b < G){
      G = a / b;
      u = used;
    }
    return ;
  }
  REP(i, N){
    if(used[i] != -1 || !check(i, used, w, s)) continue;
    used[i] = cnt;
    dfs(sum + w[i], cnt - 1, used, w, s, f);
    used[i] = -1;
  }
}

int main() {
  while(cin >>N){
    G = INF;
    u = vector<int>(N, -1);
    vector<int> w(N), s(N), used(N, -1);
    vector<string> f(N);
    REP(i, N) cin >>f[i] >>w[i]>>s[i];
    dfs(0, N, used, w, s, f);
    FOR(i, 1, N + 1) REP(j, N) if(u[j] == i) cout <<f[j] <<endl;
  }
  return 0;
}

C++: // 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> bool chmin(T &a, T b) {
    if(a > b) {
        a = min(a, b);
        return true;
    }
    else return false;
}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
struct Elem {
    string name;
    int weight, limit;
};

int dp[1 << 11];
vector<string> vec[1 << 11];

signed main() {
    int N;
    while(cin >> N, N) {
        vector<Elem> elems;
        for(int i=0; i<N; i++) {
            string name; int weight, limit;
            cin >> name >> weight >> limit;
            elems.push_back(Elem{name, weight, limit});
        }

        fill(dp, dp + (1<<N), INF);
        dp[0] = 0;

        for(int bit=0; bit<(1<<N); bit++) {
            int coeff = N - __builtin_popcount(bit);
            int sum = 0;
            for(int i=0; i<N; i++) {
                if(bit >> i & 1) sum += elems[i].weight;
            }
            for(int i=0; i<N; i++) {
                if((bit >> i & 1) or (sum > elems[i].limit)) continue;
                int nbit = bit | (1 << i);
                if(chmin(dp[nbit], dp[bit] + coeff * elems[i].weight)) {
                    vec[nbit] = vec[bit];
                    vec[nbit].push_back(elems[i].name);
                }
            }
        }

        vector<string> ans = vec[(1<<N) - 1];
        reverse(ans.begin(), ans.end());
        for(int i=0; i<ans.size(); i++) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}