def solve(placed, w1, w2):

  n = len(N) - len(placed)

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

  if x == []:

    a = tuple(placed)

    D1[a] = w1

    D2[a] = w2

    return

  

  for e in x:

    w = Food[e][0]

    if w2 > Food[e][1]: return

    a = w1 + w * n

    b = w2 + w

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

  return



while 1:

  n = eval(input())

  if n==0: break

  D1 = {}

  D2 = {}

  Name = {}

  Food = {}

  N = list(range(n))

  for i in N:

    a = input().split()

    Food[i] = list(map(int, a[1:]))

    Name[i] = a[0]

    

  solve([], 0, 0)

  

  Index, e = sorted(list(D1.items()), key = lambda x: x[1])[0]

  for e in list(Index)[::-1]:

    print(Name[e])
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 = Food[0][e]

    if w2 > Food[1][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

  Food = {}

  weight = 1e9

  N = list(range(n))

  x = []

  for i in N:

    a = input().split()

    x.append(list(map(int, a[1:]))+[a[0]])

  Food = list(zip(*sorted(x)))

  solve([], 0, 0)

  for e in D[::-1]:

    print(Food[2][e])
def solve(placed, w1, w2):
    n = len(N) - len(placed)
    x = list(set(N) - set(placed))
    if x == []:
        a = tuple(placed)
        D1[a] = w1
        D2[a] = w2
        return
    for e in x:
        w = Food[e][0]
        if w2 > Food[e][1]:
            return
        a = w1 + w * n
        b = w2 + w
        solve(placed + [e], a, b)
    return


while 1:
    n = eval(input())
    if n == 0:
        break
    D1 = {}
    D2 = {}
    Name = {}
    Food = {}
    N = list(range(n))
    for i in N:
        a = input().split()
        Food[i] = list(map(int, a[1:]))
        Name[i] = a[0]
    solve([], 0, 0)
    Index, e = sorted(list(D1.items()), key=lambda x: x[1])[0]
    for e in list(Index)[::-1]:
        print(Name[e])

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 = Food[0][e]
        if w2 > Food[1][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
    Food = {}
    weight = 1e9
    N = list(range(n))
    x = []
    for i in N:
        a = input().split()
        x.append(list(map(int, a[1:])) + [a[0]])
    Food = list(zip(*sorted(x)))
    solve([], 0, 0)
    for e in D[::-1]:
        print(Food[2][e])

+    global weight, D -        a = tuple(placed) -        D1[a] = w1 -        D2[a] = w2 +        if weight > w1: +            D = placed +            weight = w1 -        w = Food[e][0] -        if w2 > Food[e][1]: +        w = Food[0][e] +        if w2 > Food[1][e]: +        if a > weight: +            return -    D1 = {} -    D2 = {} -    Name = {} +    weight = 1e9 +    x = [] -        Food[i] = list(map(int, a[1:])) -        Name[i] = a[0] +        x.append(list(map(int, a[1:])) + [a[0]]) +    Food = list(zip(*sorted(x))) -    Index, e = sorted(list(D1.items()), key=lambda x: x[1])[0] -    for e in list(Index)[::-1]: -        print(Name[e]) +    for e in D[::-1]: +        print(Food[2][e])