#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include<iostream>
#include<cmath>

struct Lunch {
	int id, weight, strongth;
	bool operator<(const Lunch that) const { return id < that.id; }
};

bool is_not_crash(const std::vector<Lunch>& lunch) {
	int sum_weight = 0;
	for (auto r = lunch.rbegin(); r != lunch.rend(); ++r) {
		if (sum_weight > r->strongth) return false;
		sum_weight += r->weight;
	}
	return true;
}
double cal_center(const std::vector<Lunch>& lunch) {
	double denominator = 0, numerator = 0;
	for (auto i = 0; i < lunch.size(); ++i) {
		denominator += lunch[i].weight;
		numerator += lunch[i].weight * (i + 1.0);
	}
	return numerator / denominator;
}
int factorial(const int n) {
	int result = 1;
	for (auto i = 2; i <= n; ++i) {
		result *= i;
	}
	return result;
}
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<std::string> names(n);
		std::vector<Lunch> lunches(n), result; 
		for (auto i = 0; i < n; ++i) {
			lunches[i].id = i;
			std::cin >> names[i] >> lunches[i].weight >> lunches[i].strongth;
		}
		double min_center = DBL_MAX;
		for (auto i = factorial(n); i > 0; --i) {
			if (is_not_crash(lunches)) {
				auto temp = cal_center(lunches);
				if (temp < min_center) {
					min_center = temp;
					result = lunches;
				}
			}
			std::next_permutation(lunches.begin(), lunches.end());
		}
		for (const auto i : result) {
			std::cout << names[i.id] << '\n';
		}
	}
}
