def solve(placed, w1, w2):

  global ans

  n = len(N) - len(placed)

  if n==0:

    ans = min(ans, [w1, placed])

    return



  for e in N:

    if e in placed: continue

    w, lim, s = Food[e]

    if w2 > lim: return

    a = w1 + w * n

    if a > ans[0]: return

    solve(placed+[e], a, w2 + w)

  return

 

while 1:

  n = eval(input())

  if n==0: break

  ans = [1e9, []]

  N = list(range(n))

  f = lambda x: list(map(int, x[1:3])) + [x[0]]

  Food = [f(input().split()) for _ in [0]*n]

  solve([], 0, 0)

  for e in ans[1][::-1]:

    print(Food[e][2])
def solve(G1, G2, w1, w2):

  global ans

  n = len(G2)

  for e in G2:

    w, lim, s = Food[e]

    a = w1 + w * n

    if w2 > lim or a > ans[0]: return

    b = G1 + [e]

    if n == 1:

      ans = min(ans, [a, b])

    else:

      x = G2[:]

      x.remove(e)

      solve(b, x, a, w2 + w)

  return

 

while 1:

  n = eval(input())

  if n==0: break

  ans = [1e9, []]

  N = list(range(n))

  f = lambda x: list(map(int, x[1:3])) + [x[0]]

  Food = [f(input().split()) for _ in [0]*n]

  solve([], N, 0, 0)

  for e in ans[1][::-1]:

    print(Food[e][2])
def solve(placed, w1, w2):
    global ans
    n = len(N) - len(placed)
    if n == 0:
        ans = min(ans, [w1, placed])
        return
    for e in N:
        if e in placed:
            continue
        w, lim, s = Food[e]
        if w2 > lim:
            return
        a = w1 + w * n
        if a > ans[0]:
            return
        solve(placed + [e], a, w2 + w)
    return


while 1:
    n = eval(input())
    if n == 0:
        break
    ans = [1e9, []]
    N = list(range(n))
    f = lambda x: list(map(int, x[1:3])) + [x[0]]
    Food = [f(input().split()) for _ in [0] * n]
    solve([], 0, 0)
    for e in ans[1][::-1]:
        print(Food[e][2])

def solve(G1, G2, w1, w2):
    global ans
    n = len(G2)
    for e in G2:
        w, lim, s = Food[e]
        a = w1 + w * n
        if w2 > lim or a > ans[0]:
            return
        b = G1 + [e]
        if n == 1:
            ans = min(ans, [a, b])
        else:
            x = G2[:]
            x.remove(e)
            solve(b, x, a, w2 + w)
    return


while 1:
    n = eval(input())
    if n == 0:
        break
    ans = [1e9, []]
    N = list(range(n))
    f = lambda x: list(map(int, x[1:3])) + [x[0]]
    Food = [f(input().split()) for _ in [0] * n]
    solve([], N, 0, 0)
    for e in ans[1][::-1]:
        print(Food[e][2])

-def solve(placed, w1, w2): +def solve(G1, G2, w1, w2): -    n = len(N) - len(placed) -    if n == 0: -        ans = min(ans, [w1, placed]) -        return -    for e in N: -        if e in placed: -            continue +    n = len(G2) +    for e in G2: -        if w2 > lim: +        a = w1 + w * n +        if w2 > lim or a > ans[0]: -        a = w1 + w * n -        if a > ans[0]: -            return -        solve(placed + [e], a, w2 + w) +        b = G1 + [e] +        if n == 1: +            ans = min(ans, [a, b]) +        else: +            x = G2[:] +            x.remove(e) +            solve(b, x, a, w2 + w) -    solve([], 0, 0) +    solve([], N, 0, 0)