QOJ.ac

QOJ

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓

#17246. Apparently Make UTPC

İstatistikler

You are given sequences of positive integers $A = (A_1, A_2, \dots, A_X)$, $B = (B_1, B_2, \dots, B_Y)$, and $C = (C_1, C_2, \dots, C_Z)$ of lengths $X$, $Y$, and $Z$, respectively. Here, $X \le Y \le Z$ holds.

You want to rearrange the elements of $C$ such that the resulting sequence contains both $A$ and $B$ as contiguous subsequences.

Determine whether it is possible to achieve this goal. If it is possible, find the lexicographically smallest sequence $C$ after the rearrangement.

You are given $T$ test cases. Solve each of them.

Input

The input is given from Standard Input in the following format:

$$\begin{aligned} &T \\ &\text{case}_1 \\ &\text{case}_2 \\ &\vdots \\ &\text{case}_T \end{aligned}$$

Each case is given in the following format:

$$\begin{aligned} &X \ Y \ Z \\ &A_1 \ A_2 \ \dots \ A_X \\ &B_1 \ B_2 \ \dots \ B_Y \\ &C_1 \ C_2 \ \dots \ C_Z \end{aligned}$$

  • All input values are integers.
  • $1 \le T \le 10^5$
  • $1 \le X \le Y \le Z \le 2 \times 10^5$
  • $1 \le A_i \le Z$
  • $1 \le B_i \le Z$
  • $1 \le C_i \le Z$
  • The sum of $X + Y + Z$ over all test cases in a single input is at most $4 \times 10^5$.

Output

Print $T$ lines. The $i$-th line should contain -1 if the goal cannot be achieved for the $i$-th test case, or the lexicographically smallest rearranged $C$ if it can be achieved.

Examples

Input 1

3
2 2 4
4 3
2 1
4 3 2 1
2 3 4
4 3
3 2 1
4 3 2 1
3 3 3
1 1 1
2 2 2
3 3 3

Output 1

2 1 4 3
4 3 2 1
-1

Note

  • In the first example, the possible rearranged sequences for $C$ are $(2, 1, 4, 3)$ and $(4, 3, 2, 1)$. Print $(2, 1, 4, 3)$, which is the lexicographically smallest.
  • In the second example, the only possible rearranged sequence for $C$ is $(4, 3, 2, 1)$. Print $(4, 3, 2, 1)$.
  • In the third example, the goal cannot be achieved. Print -1.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2918EditorialOpenHashc20262110View
#1405EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.