#C2384. Book Organizer Challenge
Book Organizer Challenge
Book Organizer Challenge
You are given one or more datasets containing a collection of books. Each dataset begins with an integer \(M\) which represents the number of books in that dataset. This is followed by \(M\) lines, each containing a book ID and its genre. Your task is to organize these books by their genres. For each dataset, you need to:
- Group the books by their genre.
- Sort the genres in alphabetical order.
- Within each genre, sort the book IDs in ascending order.
- For each genre group, first print the genre name, then list the sorted book IDs on separate lines. Separate different genre groups with a blank line. If there are multiple datasets, separate the outputs of consecutive datasets with an additional blank line.
If a dataset contains no books (i.e. \(M = 0\)), simply print nothing for that dataset.
inputFormat
The first line of input contains an integer \(T\) representing the number of datasets.
For each dataset, the first line contains an integer \(M\) (the number of books).
This is followed by \(M\) lines, each containing a book ID (an integer) and a genre (a string), separated by a space.
outputFormat
For each dataset, output the organized list of books. For each genre, first print the name of the genre on one line, then print the sorted book IDs (in ascending order) each on a new line. Insert a blank line between different genres, and if there are multiple datasets, separate their outputs by an additional blank line. Do not print any extra blank lines at the end.
## sample1
3
102 Fiction
203 NonFiction
101 Fiction
Fiction
101
102
NonFiction
203
</p>