#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string f[11]; int n, s[11], w[11], p[11], q[11];
bool ok() {
	for (int i = 0; i < n - 1; i++) {
		int r = 0;
		for (int j = i + 1; j < n; j++) r += w[p[j]];
		if (r > s[p[i]]) return false;
	}
	return true;
}
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> f[i] >> w[i] >> s[i];
		for (int i = 0; i < n; i++) p[i] = i, q[i] = -1;
		do {
			if (ok()) {
				if (q[0] == -1) for (int i = 0; i < n; i++) q[i] = p[i];
				else {
					int sum1 = 0, sum2 = 0;
					for (int i = 0; i < n; i++) sum1 += w[p[i]] * (i + 1), sum2 += w[q[i]] * (i + 1);
					if (sum1 < sum2) for (int i = 0; i < n; i++) q[i] = p[i];
				}
			}
		} while (next_permutation(p, p + n));
		for (int i = 0; i < n; i++) cout << f[q[i]] << endl;
	}
}