/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.*;
/**
*
* @author alpha-pc
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
String line = sc.nextLine();
String[] sp;
String[] name = new String[n];
int[] rez = new int[n];
for (int i = 0; i < n; i++) {
line = sc.nextLine();
sp = line.split(" ");
name[i] = sp[0] + " " + sp[1];
for (int j = 2; j < 2 + m; j++) {
rez[i] += Integer.valueOf(sp[j]);
}
}
for (int j = 0; j < name.length - 1; j++) {
for (int i = 0; i < name.length - j - 1; i++) {
if (rez[i] < rez[i + 1]) {
int tempRez = rez[i];
rez[i] = rez[i + 1];
rez[i + 1] = tempRez;
String tempName = name[i];
name[i] = name[i + 1];
name[i + 1] = tempName;
}
}
}
int position = 1;
System.out.println(name[0] + " " + rez[0] + " " + position);
for (int i = 1; i < n; i++) {
if(rez[i] != rez[i - 1]) {
position++;
}
System.out.println(name[i] + " " + rez[i] + " " + position);
}
}
}