import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;


void main(){
    while(true) {
        auto n = readInt();
        if(n == 0) {
            return;
        }
        string[] f;
        int[] w, s;
        foreach(i; iota(n)) {
            auto l = readln().chomp().split(" ");
            f ~= l[0];
            w ~= l[1].to!int;
            s ~= l[2].to!int;
        }
        Tuple!(int, int[]) calc(int n, int k, int[] l, bool[] used) {
            if(k < n) {
                auto ret = tuple(int.max, new int[](0));
                foreach(i; iota(n)) {
                    if(!used[i]) {
                        used[i] = true;
                        auto tmp = calc(n, k+1, l ~ i, used);
                        ret = min(ret, tmp);
                        used[i] = false;
                    }
                }
                return ret;
            } else {
                int sf;
                foreach_reverse(i; iota(n)) {
                    if(s[l[i]] < sf) {
                        return tuple(int.max, new int[](0));
                    }
                    sf += w[l[i]];
                }
                return tuple(zip(iota(1, n+1), l).map!(a => a[0] * w[a[1]]).sum, l);
            }
        }
        auto ans = calc(n, 0, new int[](0), new bool[](n))[1];
        ans.map!(a => f[a]).each!writeln();
    }
}