// Arup Guha
// 12/21/2015
// Solution to UCF 1987 HS Contest Problem: Contest Scoreboard

import java.util.*;

public class contest {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int teams = stdin.nextInt();
		int problems = stdin.nextInt();

		team[] list = new team[teams];

		// Read through each team.
		for (int i=0; i<teams; i++) {
			list[i] = new team(i+1);

			// Process each problem.
			for (int j=0; j<problems; j++) {
				int min = stdin.nextInt();
				int subs = stdin.nextInt();
				list[i].add(min, subs);
			}
		}

		// Sort it!
		Arrays.sort(list);

		// Print header and each team line - annoying 15 character field widths for each...
		System.out.println("          PLACE           TEAM NUMBER CORRECT PENALTY POINTS");
		for (int i=0; i<teams; i++)
			System.out.printf("%15d%15d%15d%15d\n", i+1, list[i].ID, list[i].correct, list[i].penalty);
	}


}

class team implements Comparable<team> {

	public int correct;
	public int penalty;
	public int ID;

	public team(int myID) {
		ID = myID;
		correct = 0;
		penalty = 0;
	}

	// Adds a problem solved at min minutes into the contest with a total of submissions submissions.
	public void add(int min, int submissions) {
		if (min > 0) {
			correct++;
			penalty += (min + 20*submissions);
		}
	}

	public int compareTo(team other) {

		// First sort by correct submissions.
		if (this.correct != other.correct)
			return other.correct - this.correct;

		// Break ties by smaller penalty.
		return this.penalty - other.penalty;
	}
}