#C3229. Find Books by Tag

    ID: 46633 Type: Default 1000ms 256MiB

Find Books by Tag

Find Books by Tag

You are given a library of books where each book has a unique name and a single unique tag. For each test case, first you are provided with an integer \(n\) representing the number of books, followed by \(n\) lines with each line containing a book name and its tag separated by a space. Then, an integer \(q\) is given representing the number of queries, followed by \(q\) lines each containing a tag to search for.

For each query, output the book names that have the queried tag, sorted in lexicographical order and separated by commas. If no book is found for a queried tag, output "No books found.". Each result must be printed on a new line.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  1. An integer \(T\) denoting the number of test cases.
  2. For each test case:
    • An integer \(n\) indicating the number of books in the library.
    • \(n\) lines, each containing a book name and a tag separated by a space.
    • An integer \(q\) representing the number of queries.
    • \(q\) lines, each containing a tag to be queried.

outputFormat

For each query in each test case, output a single line:

  • If there are matching books, print the book names sorted in lexicographical order, separated by commas (,).
  • If no books match the queried tag, print "No books found.".

## sample
1
5
MobyDick Fiction
Hamlet Drama
OfMiceAndMen Fiction
Dune SciFi
Frankenstein Horror
3
Drama
Fiction
Fantasy
Hamlet

MobyDick,OfMiceAndMen No books found.

</p>