#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

struct food {
	string f; int w, s;
};
int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<food>v(n);
		int sum = 0;
		rep(i, n) {
			string f; int w, s; cin >> f >> w >> s;
			v[i] = { f,w,s }; sum += w;
		}
		sort(v.begin(), v.end(), [](food a, food b) {return a.w > b.w; });
		while (!v.empty()) {
			int i = 0;
			while (v[i].s < sum - v[i].w)i++;
			sum -= v[i].w;
			cout << v[i].f << endl;
			v.erase(v.begin() + i);
		}
	}
}