// Arup Guha
// 3/22/2026
// Example illustrating ArrayList and StringTokenizer
// Sorting People by Age - People class

import java.util.*;

public class SortPeople {

	public static void main(String[] args) {
	
		// Get the number of names.
		Scanner stdin = new Scanner(System.in);
		int n = Integer.parseInt(stdin.nextLine().trim());
		
		// Read in names.
		ArrayList<Person> list = new ArrayList<Person>();
		for (int i=0; i<n; i++) {
		
			// Get the next line.
			String line = stdin.nextLine();
			
			// We'll have to split these tokens here by white space.
			StringTokenizer tok = new StringTokenizer(stdin.nextLine());
			String mydate = tok.nextToken();
			String mytime = tok.nextToken();
			
			// Now create the person object.
			Person tmp = new Person(line, mydate, mytime);
			
			// Add them to the list.
			list.add(tmp);
		}
		
		// Since an ArrayList is a Collection, we use Collections.sort not Arrays.sort.
		Collections.sort(list);
		
		// Print out the sorted list.
		for (int i=0; i<list.size(); i++)
			System.out.println(list.get(i));
	}
}