def solve(placed, w1, w2):

  global weight, D

  n = len(N) - len(placed)

  x = list(set(N) - set(placed))

  if x == []:

    if weight > w1:

      D = placed

      weight = w1

    return

   

  for e in x:

    w = W[e]

    if w2 > S[e]: return

    a = w1 + w * n

    if a > weight: return

    b = w2 + w

    solve(placed+[e], a, b)

  return

 

while 1:

  n = eval(input())

  if n==0: break

  D = []

  weight = 1e9

  N = list(range(n))

  f = lambda x: [int(x[1]),int(x[2]),x[0]]

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

  W, S, Name = list(zip(*sorted(x)))

  solve([], 0, 0)

  for e in D[::-1]:

    print(Name[e])
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(placed, w1, w2):
    global weight, D
    n = len(N) - len(placed)
    x = list(set(N) - set(placed))
    if x == []:
        if weight > w1:
            D = placed
            weight = w1
        return
    for e in x:
        w = W[e]
        if w2 > S[e]:
            return
        a = w1 + w * n
        if a > weight:
            return
        b = w2 + w
        solve(placed + [e], a, b)
    return


while 1:
    n = eval(input())
    if n == 0:
        break
    D = []
    weight = 1e9
    N = list(range(n))
    f = lambda x: [int(x[1]), int(x[2]), x[0]]
    x = [f(input().split()) for _ in [0] * n]
    W, S, Name = list(zip(*sorted(x)))
    solve([], 0, 0)
    for e in D[::-1]:
        print(Name[e])

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])

-    global weight, D +    global ans -    x = list(set(N) - set(placed)) -    if x == []: -        if weight > w1: -            D = placed -            weight = w1 +    if n == 0: +        ans = min(ans, [w1, placed]) -    for e in x: -        w = W[e] -        if w2 > S[e]: +    for e in N: +        if e in placed: +            continue +        w, lim, s = Food[e] +        if w2 > lim: -        if a > weight: +        if a > ans[0]: -        b = w2 + w -        solve(placed + [e], a, b) +        solve(placed + [e], a, w2 + w) -    D = [] -    weight = 1e9 +    ans = [1e9, []] -    f = lambda x: [int(x[1]), int(x[2]), x[0]] -    x = [f(input().split()) for _ in [0] * n] -    W, S, Name = list(zip(*sorted(x))) +    f = lambda x: list(map(int, x[1:3])) + [x[0]] +    Food = [f(input().split()) for _ in [0] * n] -    for e in D[::-1]: -        print(Name[e]) +    for e in ans[1][::-1]: +        print(Food[e][2])