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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)
#define EPS (1e-8)

string name[10];
int w[10], s[10];
int num[10], an[10];
double mi;
int n;

void dfs(int pos, double sum, double g) {
	if (pos == n) {
		g /= (double)sum;
		if (mi > g + EPS) {
			mi = g;
			REP(i, 10) an[i] = num[i];
		}
	}
	else {
		REP(i, n) if (num[i] == -1 && s[i] >= sum - EPS) {
			num[i] = pos;
			dfs(pos + 1, sum + w[i], g + w[i] * (n - pos));
			num[i] = -1;
		}
	}
}

int main() {
	while (cin >> n, n) {
		REP(i, n) cin >> name[i] >> w[i] >> s[i];

		fill(num, num + n, -1);
		fill(an, an + n, -1);
		mi = INF;

		dfs(0, 0.0, 0.0);
		vector<int> ans(n);
		for (int i = n - 1; i >= 0; i--) REP(j, n) if (an[j] == i) ans[n - i - 1] = j;
		REP(i, n) cout << name[ans[i]] << endl;
	}
	return 0;
}