#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;


int main()
{
	int n;
	while (cin >> n, n) 
	{
		vector<pair<pair<int, int>,string> > v;
		bool used[20] = {0};
		int sum = 0;
		rep(i,n){
			string f;
			int w, s;
			cin >> f >> w >> s;
			v.push_back({{w,s},f });
			sum += w;
		}

		sort(v.begin(), v.end());
		reverse(v.begin(),v.end());

		rep(j,n){
			rep(i, n) {
				if (!used[i]) {
					if (v[i].first.second >= sum - v[i].first.first) {
						cout << v[i].second << endl;
						sum -= v[i].first.first;
						used[i] = 1;
						break;
					}
				}
			}
			sort(v.begin(), v.end());
			reverse(v.begin(), v.end());
		}
	}
	return 0;
}