#P1918B. Minimize Inversions

    ID: 10346 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>constructive algorithmsdata structuresgreedyimplementationsortings*900

Minimize Inversions

Description

You are given two permutations aa and bb of length nn. A permutation is an array of nn elements from 11 to nn where all elements are distinct. For example, an array [2,1,32,1,3] is a permutation, but [0,10,1] and [1,3,11,3,1] aren't.

You can (as many times as you want) choose two indices ii and jj, then swap aia_i with aja_j and bib_i with bjb_j simultaneously.

You hate inversions, so you want to minimize the total number of inversions in both permutations.

An inversion in a permutation pp is a pair of indices (i,j)(i, j) such that i<ji < j and pi>pjp_i > p_j. For example, if p=[3,1,4,2,5]p=[3,1,4,2,5] then there are 33 inversions in it (the pairs of indices are (1,2)(1,2), (1,4)(1,4) and (3,4)(3,4)).

The first line contains an integer tt (1t200001 \leq t \leq 20\,000) — the number of test cases.

Each test case consists of three lines. The first line contains an integer nn (1n21051 \leq n \leq 2\cdot10^5) — the length of the permutations aa and bb. The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \leq a_i \leq n) — permutation aa. The third line contains bb in a similar format.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5.

For each test case, output two permutations aa' and bb' (in the same format as in the input) — the permutations after all operations. The total number of inversions in aa' and bb' should be the minimum possible among all pairs of permutations that can be obtained using operations from the statement.

If there are multiple solutions, print any of them.

Input

The first line contains an integer tt (1t200001 \leq t \leq 20\,000) — the number of test cases.

Each test case consists of three lines. The first line contains an integer nn (1n21051 \leq n \leq 2\cdot10^5) — the length of the permutations aa and bb. The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \leq a_i \leq n) — permutation aa. The third line contains bb in a similar format.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5.

Output

For each test case, output two permutations aa' and bb' (in the same format as in the input) — the permutations after all operations. The total number of inversions in aa' and bb' should be the minimum possible among all pairs of permutations that can be obtained using operations from the statement.

If there are multiple solutions, print any of them.

Sample Input 1

3
5
1 2 3 4 5
5 4 3 2 1
3
3 1 2
3 1 2
6
2 5 6 1 3 4
1 5 3 6 2 4

Sample Output 1

3 2 5 1 4
3 4 1 5 2
1 2 3
1 2 3
2 3 4 6 5 1
1 2 4 3 5 6

Note

In the first test case, the minimum possible number of inversions is 1010.

In the second test case, we can sort both permutations at the same time. For this, the following operations can be done:

  • Swap the elements in the positions 11 and 33 in both permutations. After the operation, a=a = [2,1,32,1,3], b=b = [2,1,32,1,3].
  • Swap the elements in the positions 11 and 22. After the operations, aa and bb are sorted.

In the third test case, the minimum possible number of inversions is 77.