import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int i, j, k;
int N = sc.nextInt();
String[] employee = new String[N];
int[][] work = new int[N][7];
int[] sum = new int[N]; for(i=0; i<N; i++) sum[i]=0;
for (i=0; i<N; i++){
employee[i] = sc.next();
for (j=0; j<7; j++){
work[i][j] = sc.nextInt();
}
}
for (i=0; i<N; i++){
for (j=0; j<7; j++){
sum[i] += work[i][j];
}
}
int tempInt = 0; String tempString = "";
for (i=0; i<N; i++){
for (j=i+1; j<N; j++){
if (sum[i] < sum[j]){
tempString = employee[i]; tempInt = sum[i];
employee[i] = employee[j]; sum[i] = sum[j];
employee[j] = tempString; sum[j] = tempInt;
}
}
}
for (i=0; i<N; i++){
System.out.printf("%s ", employee[i]); System.out.println(sum[i]);
}
}
}
동점인 경우에도 잘 나오는것같은데