try: input=raw_input
except: pass

import sys

def score(p, e):
  min = 10
  max = 0
  sum = 10 * p
  for x in e:
    if x > max:
      max = x
    if x < min:
      min = x
    sum = sum + x
  return sum - min - max

N = int(input())
C = []
scores = []
best = [0,0,0]
for i in range(N):
  s = input().split()
  C.append(s[0])
  p = int(s[1])
  e = list(map(int,s[2:]))
  sc = score(p, e)
  scores.append(sc)
  if sc > best[0]:
    best[2] = best[1]
    best[1] = best[0]
    best[0] = sc
  elif sc > best[1]:
    best[2] = best[1]
    best[1] = sc
  elif sc > best[2]:
    best[2] = sc
for j in range(3):
  for i in range(N):
    if scores[i] == best[j]:
      print(C[i] + " " + str(scores[i]))
      scores[i] = -1
