#K66202. Organize Books by Authors
Organize Books by Authors
Organize Books by Authors
Maria loves reading books and wants to organize her collection by authors. Given a list of books where each book is represented in the format Author_Title
, your task is to group the books by their authors.
For each test case, the first line contains an integer $N$ (the number of books). The following $N$ lines each contain a string in the format Author_Title
. The output should display each author followed by their sorted book titles. Authors must be listed in lexicographical order. For each author, the book titles should also be sorted in lexicographical order. Separate outputs for different test cases with an empty line.
inputFormat
The input is read from stdin and has the following format:
T N Book_1 Book_2 ... Book_N ... (repeated for T test cases)
Here, T is the number of test cases and N is the number of books in that test case.
outputFormat
For each test case, print the authors and their books on separate lines. For each author, print the author's name followed by a space-separated list of their book titles. The authors must be printed in lexicographical order, and the book titles for each author must also be sorted in lexicographical order. Separate the outputs for different test cases by an empty line.
## sample1
2
Rowling_Potter1
Rowling_Potter2
Rowling Potter1 Potter2
</p>