The city of Lletya is known for its violent and unpredictable weather. As a result, residents cannot go outside to meet one another in-person, and are forced to communicate with telephones. To ease communications, the government of Lletya built a network of phone switch stations, which calls are forwarded through. As lightning can interfere with wireless signals, switch stations are physically connected with telephone wires. As maintenance is expensive, switch stations are connected with as little wire as possible, so there is exactly one way to forward a call between any two switch stations.
Lletya outsources its switch stations to phone companies. The -th phone company owns of the switch stations, though multiple companies can own the same station. A call between residents subscribed to the -th phone company must enter and leave through a pair of switch stations company owns. Of course, the call can be transmitted through switch stations not owned by company , as long as company owns the starting and ending stations. A call can enter and leave the same switch station.
A switch station can only process one call at a time: whether it be sending, receiving, or transmitting the call: calls conflict if they need to use the same switch station. We say that company interferes with company if a call under company can conflict with a call under company , or vice versa. Consider the set of switch stations wired in the diagrams below, and suppose that company owns stations , company owns stations and company owns stations . Then company interferes with company , since a call between stations and under company conflicts with a call between stations and at station (see left diagram). Company interferes with company since a call between stations and under company conflicts with a call between stations and under company at station (see right diagram). However, no call under company can conflict with a call under company , so companies and do not interfere.
While residents heavily dislike interferences, they are forced to tolerate them. However, one rainy morning, the dark clouds above Lletya began to part. As the sky cleared and violent storms ceased, residents left their homes to meet in-person instead of over the phone. As a result, the government plans to shut down some phone companies to cut costs.
Companies are not happy with this, so the government must provide a good reason for each shutdown. Namely, if companies and are both shut down, then they must interfere with one another (the government can use delays from interference as an excuse). Moreover, the government also wants to prevent one of the remaining phone companies from becoming too profitable: thus, for any triplet of companies remaining after the shutdown, if company interferes with company , and company interferes with company , then company must interfere with company .
Is there a non-empty set of companies the government can shut down?
Constraints
It is guaranteed that the sum of over all test cases will not exceed .
It is guaranteed that the sum of over all test cases will not exceed .
It is guaranteed that the sum of over all test cases will not exceed .
Subtask 1 [10%]
The switch stations are wired in a line (more precisely, stations and are connected for all ).
Subtask 2 [15%]
There is at most one switch station of degree .
Subtask 3 [75%]
No additional constraints.
Input Specification
On the first line, an integer , the number of test cases.
The first line of each test case contains two space-separated integers and , the number of switch stations and phone companies in Lletya.
The next lines each contain two space-separated integers, and , indicating that stations and are connected with wires.
The next lines each contain an integer , the number of stations company owns, followed by unique space-separated integers , the stations company owns.
Output Specification
For each test case, output one line, consisting of an integer , followed by unique space-separated integers , indicating a possible non-empty set of companies the government can shut down. If there are multiple answers, output any of them. If there is no non-empty set of companies the government can shut down to meet its requirements, output .
Scoring
If your program outputs for impossible cases, but an incorrect set of companies otherwise, the grader will award of the points for the test case.
If your program outputs a malformatted set of companies (for example, if , or contains repetitions), the grader will throw a Presentation Error.
Sample Input
3
5 5
1 2
2 3
3 4
4 5
2 1 2
1 2
2 2 3
3 2 3 4
2 3 5
9 3
1 2
2 3
3 4
3 5
3 6
6 7
5 8
5 9
2 1 6
2 4 8
3 5 8 9
13 8
1 2
2 3
2 4
4 5
5 6
6 7
7 8
8 9
7 10
10 11
10 12
10 13
3 2 5 6
4 2 4 5 6
2 1 7
5 4 6 7 10 13
3 7 8 9
2 11 12
3 10 11 12
2 2 3
Sample Output
2 3 4
1 2
2 3 4
Explanation for Sample
For test case , a call from station to under company and a call from station to under company both need to use station . Thus, companies and can both be shut down.
Test case is described in the problem statement.
Test case satisfies the constraints of all subtasks.
Test cases and satisfy the constraints of subtask .
Comments