import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringJoiner;

public class Vincent3 {

	private static void read() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String[] C = new String[N];
		int[] P = new int[N];
		int[][] E = new int[N][6];
		for (int i = 0; i < N; i++) {
			String[] line = br.readLine().split(" ");
			C[i] = line[0];
			P[i] = Integer.parseInt(line[1]);
			for (int j = 0; j < 6; j++) {
				E[i][j] = Integer.parseInt(line[j + 2]);
			}
		}
		br.close();
		int[] score = new int[N];
		int[] top3 = new int[3];
		for (int i = 0; i < N; i++) {
			int max = 0;
			int min = 10;
			int sum = 10 * P[i];
			for (int j = 0; j < 6; j++) {
				sum += E[i][j];
				if (E[i][j] > max) {
					max = E[i][j];
				}
				if (E[i][j] < min) {
					min = E[i][j];
				}
			}
			sum -= min + max;
			score[i] = sum;
			if (sum > top3[0]) {
				top3[2] = top3[1];
				top3[1] = top3[0];
				top3[0] = sum;
			} else if (sum > top3[1]) {
				top3[2] = top3[1];
				top3[1] = sum;
			} else if (sum > top3[2]) {
				top3[2] = sum;
			}
		}

		int count = 0;
		StringJoiner sj = new StringJoiner("\n");
		while (count < 3) {
			int rank = count;
			for (int i = 0; i < N; i++) {
				if (score[i] == top3[rank]) {
					sj.add(C[i] + " " + score[i]);
					count++;
					score[i] = -1;
				}
			}
		}
		System.out.println(sj.toString());
	}

	public static void main(String[] args) throws IOException {
		read();
	}
}

