#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, w[1000], s[1000];
string S[1000]; vector<int>b; int maxn;
int main() {
	while (true) {
		cin >> n; b.clear(); maxn = 1 << 30;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> S[i] >> w[i] >> s[i];
		}
		vector<int>a(n, 0);
		for (int i = 0; i < n; i++)a[i] = i;
		do {
			int sum2 = 0;
			for (int i = 0; i < n; i++) {
				int sum = 0;
				for (int j = i + 1; j < n; j++) {
					sum += w[a[j]];
				}
				if (sum > s[i]) goto E;
			}
			for (int i = 0; i < n; i++)sum2 += i*w[i];
			if (maxn > sum2)b = a;
		E:;
		} while (next_permutation(a.begin(), a.end()));
		for (int i = 0; i < n; i++)cout << S[a[i]] << endl;
	}
	return 0;
}