#K65072. Book Genre Filtering
Book Genre Filtering
Book Genre Filtering
In this problem, you are given several test cases. Each test case consists of a book catalog and a target genre. Each book is represented by its unique ISBN and is associated with one or more genres. Your task is to filter out all books that are tagged with the target genre and then output the sorted unique ISBNs (sorted in increasing lexicographical order) separated by a single space.
Formally, for each test case, you are given an integer \(N\) followed by \(N\) lines, each containing an ISBN and a list of genres. After these \(N\) lines, there is one line that specifies the target genre. You must output one line per test case containing the sorted unique ISBNs of books that include the target genre.
Note: ISBNs should be output in lexicographical order with duplicates removed.
inputFormat
The input consists of multiple test cases. The first line contains an integer \(T\), the number of test cases. For each test case, the input is structured as follows:
- A line containing an integer \(N\) (the number of books).
- \(N\) lines, each containing an ISBN followed by one or more space-separated genres.
- A line containing the target genre to filter by.
outputFormat
For each test case, output a single line containing the sorted unique ISBNs (separated by a single space) of the books that belong to the target genre.
## sample2
3
12345 fiction romance
45678 action romance
78901 fiction mystery
fiction
3
13579 history
24680 fantasy
97531 history mystery
history
12345 78901
13579 97531
</p>