Pointers
시간 제한3초메모리 제한2048 MB
각 노드가 이웃을 가리키는 포인터를 순환시키며 이동할 때, 무한히 반복되는 (현재 노드, 포인터 배열) 상태를 하나 출력한다.
문제
You are given a connected undirected graph with nodes and edges. Each node has an ordered list of its neighbors, and an arrow pointing to one of its neighbors . Initially, is the first neighbor in .
You start at node , and repeat the following process infinitely many times:
- Let be the node at which you are currently located. Move from to .
- Increment to the next neighbor in cyclically.
See the sample notes for an example of this process.
Consider the list over the course of this process, as well as the current node . We call this a "state".
Print any state that appears an infinite amount of times.
입력
The first line of the input contains a single integer () --- the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers , , and (, , ) --- the number of vertices and edges in the graph, and the starting node, respectively.
The -th of the next lines describes the ordered list of neighbors of . It begins with an integer () --- the number of neighbors of . This is followed by distinct integers (, ) --- the neighbors of .
It is guaranteed that if is a neighbor of , then is a neighbor of . It is also guaranteed that there are undirected edges in total.
Across all test cases, it is guaranteed that the sum of is at most , and the sum of is at most .
출력
For each test case print any state that repeats infinitely in the format .
힌트
Let's visualize the third sample case. The red node represents your current position, and the arrow pointing out from each node points at node . Here is how the graph looks at the start of the process, and after each of the next steps:

We can see that after operations have been performed, we have reached the initial state once again, and our current location (node ) is the same as it was at the beginning. Therefore, a valid answer is to simply print the initial state.