LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Merge Two Sorted Arrays

EasyProblem #59
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Both lists arrive already sorted - you should not have to sort anything.

In the school of little yellow ants the teacher has just finished grading a test. Half of the class wrote group A and the other half wrote group B, so he graded the two groups separately and ended up with two lists of scores, each one already sorted in non-decreasing order.

Now he needs a single ranking of the whole class. Help him turn the two sorted lists into one sorted list containing every score from both of them.

Input

First line of input will be a single integer t - the number of testcases.
The first line of each testcase contains two integers m and n - the number of ants in group A and in group B.
The second line contains m integers a1​≤a2​≤⋯≤am​ - the scores in group A.
The third line contains n integers b1​≤b2​≤⋯≤bn​ - the scores in group B.

Output

For every testcase print a single line with all m+n scores in non-decreasing order, separated by one space.

Example

Input
2
4 3
1 3 5 7
2 4 5
1 5
10
1 2 3 4 5
Output
1 2 3 4 5 5 7
1 2 3 4 5 10

In the first testcase the two lists take turns, and the score 5 appears in both groups so it appears twice in the ranking. In the second one group B is used up completely before the single ant from group A gets its place at the end.

Constraints

1≤t≤10
1≤m,n≤25000
0≤ai​,bi​≤109
The sum of m+n over all testcases does not exceed 105
Both lists are given in non-decreasing order


This problem was adapted, with permission, from Objedinjavanje, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit