#include <bits/stdc++.h>

using namespace std;

class FoodInfor {
public:
	string name;
	int weight;
	int limit;
};

FoodInfor FoodData[10];
int TableIndex[10], Result[10];


bool checkWeight(int n) {
	int sum = 0;

#if 0
	for (int i = n-1; i > 0; i--) {
		sum += FoodData[TableIndex[i]].weight;
		if (sum > FoodData[TableIndex[i - 1]].limit) {
			return false;
		}
	}
#else
	for (int i = 0; i < n - 1; i++) {
		sum += FoodData[TableIndex[i]].weight;
		if (sum > FoodData[TableIndex[i + 1]].limit) {
			return false;
		}
	}
#endif
	
	return true;
}

int getG(int n) {
	int G = 0;
	for (int i = 0; i < n; i++) {
		G += FoodData[TableIndex[i]].weight * (n-i);
	}
	return G;
}

int main() {
	int n, tmpG, minG;

	while (cin>>n, n) {
		for (int i = 0; i < n; i++) {
			cin >> FoodData[i].name >> FoodData[i].weight >> FoodData[i].limit;
		}

		for (int i = 0; i < n; i++) {
			TableIndex[i] = i;
		}

		minG = INT_MAX;
		do {
			if (checkWeight(n) && minG > (tmpG = getG(n))) {
				//copy(TableIndex, TableIndex + n, Result);	//OK
				//memmove(Result, TableIndex, n);			//NG
				for (int i = 0; i < n; i++) {
					Result[i] = TableIndex[i];
				}
				minG = tmpG;
			}
		} while (next_permutation(TableIndex, TableIndex + n));

		for (int i = 0; i < n; i++) {
			cout << FoodData[Result[n-1-i]].name << endl;
		}
	}
}
