#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

struct food
{
	int f, w, s;
};
struct Sorter
{
	bool operator()(const food& a, const food& b)
	{
		return a.f < b.f;
	}
};
int main()
{
	char name[10][32];
	int n;
	while (scanf("%d", &n), n)
	{
		food foods[10];
		for (int i = 0; i < n; ++i)
		{
			int w, s;
			scanf("%s %d %d", name[i], &w, &s);
			foods[i].f = i;
			foods[i].w = w;
			foods[i].s = s;
		}

		const double Inf = 1e12;
		double minG = Inf;
		int order[10];
		do
		{
			int sumW = 0;
			double g = 0;
			bool ok = true;
			for (int i = 0; i < n; ++i)
			{
				if (sumW > foods[i].s)
				{
					ok = false;
					break;
				}
				sumW += foods[i].w;
				g += (n-i) * foods[i].w;
			}
			g /= sumW;
			if (ok && g < minG)
			{
				minG = g;
				for (int i = 0; i < n; ++i)
					order[i] = foods[i].f;
			}
		} while (next_permutation(foods, foods+n, Sorter()));
		for (int i = n-1; i >= 0; --i)
			printf("%s\n", name[order[i]]);
	}

	return 0;
}