#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, w[1000], s[1000];
string S[1000]; vector<int>b; int maxn = 100000000;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S[i] >> w[i] >> s[i];
	}
	vector<int>a(n, 0);
	for (int i = 0; i < n; i++)a[i] = i;
	do {
		int sum2 = 0;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = i + 1; j < n; j++) {
				sum += w[a[j]];
			}
			if (sum > s[i]) goto E;
		}
		for (int i = 0; i < n; i++)sum2 += i*w[i];
		if (maxn > sum2)b = a;
	E:;
	} while (next_permutation(a.begin(), a.end()));
	for (int i = 0; i < n; i++)cout << S[a[i]] << endl;
	return 0;
}