Problem: Given two arrays and , both of length . Elements of both arrays indexed from to . You are constructing a directed graph, where edge from to () exists if .
A vertex is called strong if there exists a path from to all other vertices.
A path in a directed graph is a chain of several vertices, connected by edges, such that moving from the vertex , along the directions of the edges, the vertex can be reached.
Your task is to find all strong vertices.
For example, if and , the graph will look like this:
The graph has only one strong vertex with number
Input Format: The first line contains an integer () — the number of test cases.
The first line of each test case contains an integer () — the length of and .
The second line of each test case contains integers () — the array .
The third line of each test case contains integers () — the array .
It is guaranteed that the sum of for all test cases does not exceed .
Output Format: For each test case, output two lines: in the first line, output the number of strong vertices, and in the second line, output all strong vertices in ascending order.
Note: The first sample is covered in the problem statement.
For the second sample, the graph looks like this:
The graph has two strong vertices with numbers and . Note that there is a bidirectional edge between vertices and .
In the third sample, the vertices are connected by a single directed edge from vertex to vertex , so the only strong vertex is .
In the fourth sample, all vertices are connected to each other by bidirectional edges, so there is a path from every vertex to any other vertex.