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

const int MAX_N = (int)1e6;
struct Data {
	std::string name;
	int weight, max_weight;
	Data() = default;
	Data(int _w, int _m, const std::string& _n) : weight(_w), max_weight(_m), name(_n) {}

	bool operator<(const Data& rhs) const {
		return (weight == rhs.weight) ? 
			(max_weight==rhs.max_weight)? 
			name < rhs.name : max_weight < rhs.max_weight : weight < rhs.weight;
	}
	bool operator>(const Data& rhs) const{
		return (weight == rhs.weight) ?
			(max_weight == rhs.weight) ?
			name > rhs.name : max_weight > rhs.max_weight : weight > rhs.weight;
	}
};


int n, sum;
std::vector<Data> data;
std::string ans[MAX_N];

int main() {
	while (1) {
		std::cin >> n;
		if (n == 0)
			break;
		sum = 0;
		int _w, _m;
		std::string _n;
		for (int i = 0; i < n; ++i) {
			std::cin >> _n >> _w >> _m;
			data.push_back(Data(_w, _m, _n));
			sum += data[i].weight;
		}

		std::sort(data.begin(), data.end(), std::greater<Data>());

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < data.size(); ++j) {
				if (data[j].max_weight >= sum - data[j].weight) {
					sum -= data[j].weight;
					ans[i] = data[j].name;
					data.erase(data.begin() + j);
					break;
				}
			}
		}
		for (int i = 0; i < n; ++i)
			std::cout << ans[i] << std::endl;
	}
	system("pause");
	return 0;
}