#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
using namespace std;

int n;
string f[10];
int w[10], s[10];
bool used[10];

void dfs(int sum, int G, int &minG, vector<string> &v, vector<string> &ans) {
	if ((int)v.size() == n) {
		if (G < minG) {
			minG = G;
			ans = v;
		}
		return ;
	}
	for (int i=0; i<n; ++i) {
		if ( ! used[i] && sum - w[i] <= s[i]) {
			used[i] = true;
			v.push_back(f[i]);
			dfs(sum-w[i], G+v.size()*w[i], minG, v, ans);
			used[i] = false;
			v.pop_back();
		}
	}
	return ;
}

int main() {
	while (cin >> n, n) {
		int sum = 0;
		for (int i=0; i<n; ++i) {
			cin >> f[i] >> w[i] >> s[i];
			sum += w[i];
		}
		memset(used, false, sizeof used);
		int minG = INT_MAX;
		vector<string> v, ans;
		dfs(sum, 0, minG, v, ans);
		for (int i=0; i<(int)ans.size(); ++i) {
			cout << ans[i] << endl;
		}
	}
	return 0;
}