Problem:
You are given an array a consisting of n integers, as well as an array b consisting of m integers.
Let LIS(c) denote the length of the longest increasing subsequence of array c. For example, LIS([2,1,1,3]) = 2, LIS([1,7,9]) = 3, LIS([3,1,2,4]) = 3.
You need to insert the numbers b1,b2,…,bm into the array a, at any positions, in any order. Let the resulting array be c1,c2,…,cn+m. You need to choose the positions for insertion in order to minimize LIS(c).
Formally, you need to find an array c1,c2,…,cn+m that simultaneously satisfies the following conditions:
- The array a1,a2,…,an is a subsequence of the array c1,c2,…,cn+m.
- The array c1,c2,…,cn+m consists of the numbers a1,a2,…,an,b1,b2,…,bm, possibly rearranged.
- The value of LIS(c) is the minimum possible among all suitable arrays c.
Input Format:
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n,m (1≤n≤2⋅105,1≤m≤2⋅105) — the length of array a and the length of array b.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array a.
The third line of each test case contains m integers b1,b2,…,bm (1≤bi≤109) — the elements of the array b.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105, and the sum of m over all test cases does not exceed 2⋅105.
Output Format:
For each test case, output n+m numbers — the elements of the final array c1,c2,…,cn+m, obtained after the insertion, such that the value of LIS(c) is minimized. If there are several answers, you can output any of them.
Note:
In the first test case, LIS(a)=LIS([6,4])=1. We can insert the number 5 between 6 and 4, then LIS(c)=LIS([6,5,4])=1.
In the second test case, LIS([1,7,2,4,5]) = 4. After the insertion, c=[1,1,7,7,2,2,4,4,5,5]. It is easy to see that LIS(c)=4. It can be shown that it is impossible to achieve LIS(c) less than 4.