// Arup Guha
// 10/12/2026
// Main class (Billboard)
// Solution to Fall 2026 COP 3330 Program #6: Billboard Top 100,0000

import java.util.*;

public class Billboard {

	final public static int CURYEAR = 2026;
	
	private ArrayList<Song> allSongs;
	private ArrayList<Song>[] songsByYear;
	
	public Billboard() {
		allSongs = new ArrayList<Song>();
		songsByYear = new ArrayList[CURYEAR+1];
		for (int i=0; i<=CURYEAR; i++)
			songsByYear[i] = new ArrayList<Song>();
	}
	
	// Adds a song to this collection.
	public void addSong(Song s) {
		
		// Add to master list.
		allSongs.add(s);
		
		// Add to the appropriate year.
		songsByYear[s.getYear()].add(s);
	}
	
	// Should only be called once the collection is finalized.
	public void sort() {
		
		// First sort all.
		Collections.sort(allSongs);
		
		// Now, by year.
		for (int i=0; i<=CURYEAR; i++)
			if (songsByYear[i].size() > 0)
				Collections.sort(songsByYear[i]);
	}
	
	// Generates all the output required by the assignment.
	public void output() {
	
		// First print everything sorted.
		for (int i=0; i<allSongs.size(); i++)
			System.out.println((i+1)+". "+allSongs.get(i));
			
		// Go through years.
		for (int year=0; year<=CURYEAR; year++) {
		
			// Skip.
			if (songsByYear[year].size() == 0) continue;
			
			// Format for non-empty years.
			System.out.println(year);
			for (int i=0; i<songsByYear[year].size(); i++)
				System.out.println((i+1)+". "+songsByYear[year].get(i));
		}
	}
	
	public static void main(String[] args) {
	
		// Get number of songs.
		Scanner stdin = new Scanner(System.in);
		int n = Integer.parseInt(stdin.nextLine());
		
		// Create a new Billboard object.
		Billboard allHits = new Billboard();
		
		// Now, read through the data and add to the object.
		for (int i=0; i<n; i++) {
		
			// Read the three lines.
			String title = stdin.nextLine();
			String artist = stdin.nextLine();
			StringTokenizer tok = new StringTokenizer(stdin.nextLine());
			
			// Parse out the numbers.
			int year = Integer.parseInt(tok.nextToken());
			int sales = Integer.parseInt(tok.nextToken());
			long streams = Long.parseLong(tok.nextToken());
			
			// Create the song object.
			Song newSong = new Song(title, artist, year, sales, streams);
			
			// Add it!
			allHits.addSong(newSong);
		}
		
		// Here's what we need to do!
		allHits.sort();
		allHits.output();
	}
}