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

public class Vincent2 {

	private static int max(int[] tab) {
		int max = tab[0];
		for (int i = 1; i < tab.length; i++) {
			if (tab[i] > max) {
				max = tab[i];
			}
		}
		return max;
	}

	private static int min(int[] tab) {
		int min = tab[0];
		for (int i = 1; i < tab.length; i++) {
			if (tab[i] < min) {
				min = tab[i];
			}
		}
		return min;
	}

	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[] score = new int[N];
		int[] P = new int[N];
		int[] E = new int[6];
		for (int i = 0; i < N; i++) {
			String[] line = br.readLine().split(" ");
			C[i] = line[0];
			score[i] = 10 * Integer.parseInt(line[1]);
			for (int j = 0; j < 6; j++) {
				E[j] = Integer.parseInt(line[j + 2]);
				score[i] += E[j];
			}
			score[i] -= min(E) + max(E);
		}
		br.close();

		int[] sortedscores = new int[N];
		int[] rank = new int[N];
		for (int i = 0; i < N; i++) {
			sortedscores[i] = score[i];
		}
		Arrays.sort(sortedscores);
		for (int i = 0; i < N; i++) {
			if (score[i] == sortedscores[N - 1]) {
				rank[i] = 1;
			} else if (score[i] == sortedscores[N - 2]) {
				rank[i] = 2;
			} else if (score[i] == sortedscores[N - 3]) {
				rank[i] = 3;
			} else {
				rank[i] = 4;
			}
		}
		for (int r = 1; r <= 3; r++) {
			for (int i = 0; i < N; i++) {
				if (rank[i] == r) {
					System.out.println(C[i] + " " + score[i]);
				}
			}
		}
	}

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

