#K58627. Merge Sorted Lists

    ID: 30685 Type: Default 1000ms 256MiB

Merge Sorted Lists

Merge Sorted Lists

You are given \( t \) test cases. For each test case, you are provided with two sorted lists of integers. Your task is to merge these two lists into one sorted list. Formally, if the two lists are \( A = [a_1, a_2, \dots, a_n] \) and \( B = [b_1, b_2, \dots, b_m] \), then the merged list \( C \) should satisfy:

\( C = sorted( A \cup B ) \)

Note that the two lists may be empty. The input is read from standard input (stdin) and the merged sorted lists are to be printed on standard output (stdout) with each merged list on a separate line.

inputFormat

The input begins with a single integer \( t \) representing the number of test cases. Each test case is described as follows:

  • The first line contains two integers \( n \) and \( m \), separated by a space, where \( n \) is the number of elements in the first list and \( m \) is the number of elements in the second list.
  • The second line contains \( n \) integers in non-decreasing order (if \( n > 0 \)); otherwise, this line will be empty.
  • The third line contains \( m \) integers in non-decreasing order (if \( m > 0 \)); otherwise, this line will be empty.

All numbers are separated by spaces.

outputFormat

For each test case, print a single line containing the merged sorted list. The numbers in the list should be separated by spaces. If both lists are empty, print an empty line.

## sample
2
3 4
1 3 5
2 4 6 8
5 3
10 12 13 14 18
7 9 15
1 2 3 4 5 6 8

7 9 10 12 13 14 15 18

</p>