Tree Equation
题号:NC14374
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 128 M,其他语言256 M
Special Judge, 64bit IO Format: %lld

题目描述

Tired of solving mathematical equations, DreamGrid starts to solve equations related to rooted trees.

Let A and B be two arbitrary  rooted trees and r(T) denotes the root of TDreamGrid has defined two basic operations:
    1.Addition. T = A + B  is built by merging the two roots r(A),r(B) into a new root r(T).That is the subtrees of A and B  (if any) become the subtrees of r(T).   
     2.Multiplication. T = A · B is built by merging r(B) with each vertex x ∈ A so that all the subtrees of r(B) become new subtrees of x.
The following picture may help you understand the operations.

Given three rooted trees A ,B and C,DreamGrid would like to find two rooted trees X and Y such A·X + B · Y = C .

输入描述:

There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:
The first line contains three integers  na,nb and nc (2 ≤ na,nb ≤ nc ≤ 105) -- the number of vertices in rooted tree A,B and C,respectively.
The second line contains na intergers a1,a2,...,ana (0 ≤ ai < i) -- where ai is the parent of the i-th vertex in tree A.
The third line contains nb intergers b1,b2,....bnb  (0 ≤ bi < i) - where bi is the parent of the i-th vertex in tree B.
The fourth line contains nc intergers c1,c2,....cnc  (0 ≤ ci < i) - where ci is the parent of the i-th vertex in tree C.
Note that if ai = 0(bi = 0 or ci = 0),then the i-th vertex is the root of the tree A (B or C)
It is guaranteed that the sum of all nc does not exceed 2×106.

输出描述:

For each test case, if you can not find a solution, output "Impossible" (without quotes) in the first line.
Otherwise, output two integers nx and ny (1 ≤ nx,ny ≤ 105) denoting the number of vertices in rooted tree  X and Y in the first line.
Then in the second line, output nx intergers x1,x2,...xnx (0 ≤ xi < i)-- where  xi is the parent of the i-th vertex in tree X.
Then in the third line, output ny intergers y1,y2,...yny (0 ≤ yi < i)-- where  yi is the parent of the i-th vertex in tree Y.
If there are multiple solutions, print any of them.
示例1

输入

复制
2
2 3 10
0 1
0 1 2
0 1 1 3 4 3 6 3 1 9
4 3 10
0 1 2 2
0 1 2
0 1 1 3 4 3 6 3 1 9

输出

复制
Impossible
2 1
0 1
0