#include <bits/stdc++.h>
using namespace std;

struct Food {
	int id;
	string name;
	int w, s;
	
	Food(){id = 0; w = 0; s = 0;}
	
	bool operator < (const Food &t) const {
		return id < t.id;
	}
};

int main()
{
	int n;
	
	while (scanf("%d", &n), n){
		vector<Food> f(n);
		
		for (int i = 0; i < n; i++){
			f[i].id = i;
			cin >> f[i].name >> f[i].w >> f[i].s;
		}
		
		vector<Food> res(n);
		int minG = 1001001001;
		
		do {
			int sum = 0;
			bool fl = false;
			for (int i = n - 1; i >= 0; i--){
				if (f[i].s < sum){
					fl = true;
					break;
				}
				sum += f[i].w;
			}
			
			if (!fl){
				int G = 0;
				for (int i = 0; i < n; i++){
					G += f[i].w * (i + 1);
				}
				
				if (minG > G){
					res = f;
					minG = G;
				}
			}
			
		} while (next_permutation(f.begin(), f.end()));
		
		for (int i = 0; i < n; i++){
			cout << res[i].name << endl;
		}
	}
	
	return 0;
}