#include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <string>
#include <algorithm>

using namespace std;

typedef pair<int, string> P;
typedef pair<int, P> Q;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		Q q;
		priority_queue<Q, vector<Q>, greater<Q> > pq;
		for (int i = 0; i < n; i++) {
			cin >> (q.second).second >> (q.second).first >> q.first;
			pq.push(q);
		}
		vector<Q> data;
		q = pq.top();
		pq.pop();
		data.push_back(q);
		int w = (q.second).first;
		while (!pq.empty()) {
			data.push_back(pq.top());
			pq.pop();
			int sum = 0;
			for (int i = 0; i < data.size()-1; i++) {
				sum += (data[i].second).first;
			}
			for (int i = data.size()-1; i > 0; i--) {
				if ((data[i].second).first < (data[i-1].second).first) {
					if (sum-(data[i-1].second).first+(data[i].second).first <= data[i-1].first) {
						sum -= (data[i-1].second).first;
						swap(data[i], data[i-1]);
					} else {
						break;
					}
				} else {
					break;
				}
			}
		}
		for (int i = data.size()-1; i >= 0; i--) {
			cout << (data[i].second).second << endl;
		}
	}
	return 0;
}