#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n;
	while(cin>>n,n){
		string name[11];
		int	w[11],s[11];
		REP(i,n)cin>>name[i]>>w[i]>>s[i];
		vector<int> seq(n);
		REP(i,n)seq[i] = i;
		int minG = INF;
		vector<int> ans;
		do{
			int sum = 0;
			int G = 0;
			bool ng = false;
			REP(i,n){
				int j = seq[i];
				if(s[j] < sum)ng = true;
				sum += w[j];
			}
			if(ng)continue;
			REP(i,n){
				int j = seq[i];
				G += (n - i) * w[j];
			}
			if(G < minG){
				minG = G;
				ans = seq;
			}
		}while(next_permutation(seq.begin(), seq.end()));
		REP(i,n){
			int j = ans[n - 1 - i];
			cout<<name[j]<<endl;
		}
	}
	return 0;
}