#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

struct food
{
	int w;
	int s;
	string name;

	bool operator < (const food& right) const {
		return w >= right.w;
	}
};

int n;
food fd[10];
string f;
int tw, ts;
bool used[10];

signed main()
{
	while (true)
	{
		cin >> n;
		if (n == 0) break;
 		rep(i,n)
		{
			cin >> f >> tw >> ts;
			fd[i].name = f;
			fd[i].w = tw;
			fd[i].s = ts;
		}

		sort(fd, fd + n);
		int wsum = 0;
		rep(i,n) wsum += fd[i].w;

		rep(i,n) used[i] = false;
		rep(i,n)
		{
			rep(j,n)
			{
				if (!used[j] && fd[j].s >= wsum - fd[j].w)
				{
					//printf("%s\n", fd[j].name);
					cout << fd[j].name << endl;
					wsum -= fd[j].w;
					used[j] = true;
					break;
				}
			}
		}
	}
}