import java.io.*;
import java.util.*;

// Test using custom comparators
public class RankList {
	
	// Our main method
	public static void main(String[] Args) {
		Scanner stdin = new Scanner(System.in);
		
		// Read in the number of users
		int numUsers = stdin.nextInt();
		
		// Create a storage method for two different comparison methods
		User[] friendArray = new User[numUsers];
		ArrayList<User> friendList = new ArrayList<User>();
		
		// Read in each users
		for (int i = 0; i < numUsers; i++) {
			
			// Read in the users description
			String name = stdin.next();
			int numProblems = stdin.nextInt();
			int rank = stdin.nextInt();
		
			// Make new friend
			friendArray[i] = new User(name, numProblems, rank);
			friendList.add(friendArray[i]);
		}
		
		// Sort my friends
		Arrays.sort(friendArray);
		
		// Print out the sorted friends by rank
		for (int i = 0; i < numUsers; i++){
			System.out.println(friendArray[i]);
		}
		System.out.println();
		
		// Print out the unsorted friends
		for (int i = 0; i < numUsers; i++){
			System.out.println(friendList.get(i));
		}
		System.out.println();
		
		// Sort the friends by problems and print them
		Collections.sort(friendList, problem_first);
		for (int i = 0; i < numUsers; i++){
			System.out.println(friendList.get(i));
		}
	}
	
	// Creat a custom comparator
	public static Comparator<User> problem_first = new Comparator<User>(){
		public int compare(User u1, User o) {
			
			// Check if the problems differ
			if (u1.numProblems != o.numProblems){
				return o.numProblems - u1.numProblems;
			}
			
			// Check if the problems are equal but the ranks differ
			if (u1.rank != o.rank){
				return o.rank - u1.rank;
			}
			
			// Sort by name since rank and problems solved are equal
			return u1.name.compareTo(o.name);
			
		}
	};
	
	// Custom class that will store the users
	public static class User implements Comparable<User>{
		
		// The values associated with a user
		private String name;
		private int numProblems;
		private int rank;
		
		// The users constructor
		User(String name, int numProblems, int rank) {
			this.name = name;
			this.numProblems = numProblems;
			this.rank = rank;
		}
		
		// Compare rank first then problems
		public int compareTo(User o){
			if (this.rank != o.rank){
				return o.rank - this.rank;
			}
			if (this.numProblems != o.numProblems){
				return o.numProblems - this.numProblems;
			}
			return this.name.compareTo(o.name);
		}
		
		// Print method for the user
		public String toString(){
			return name + " " + numProblems + " " + rank;
		}
	}
}