Merge two sorted linked lists

Problem Statement

Given two sorted linked lists, merge them into a single, sorted linked list and remove duplicate values. Keep in mind that either linked list may be empty.


Example

listA: [1, 3, 7], also represented as 1->3->7->NULL

listB: [1,2], also represented as 1->2->NULL

The resulting list of merging listA and listB is: [1,2,3,7], also represented as 1->2->3->7->NULL



Input Format

The first line contains a single integer t, the number of test cases.

The format for each test case is as follows:

The first line contains an integer n , the length of the first linked list.

The next n lines contain an integer each, the elements of the linked list.

The next line contains an integer m, the length of the second linked list.

The next m lines contain an integer each, the elements of the second linked list.



Constraints

  • 1 <= t <= 10
  • 0 <= n,m <= 1000
  • 1 ≤list[i]≤10^3, where list[i] is the ith element of the list


Output Format

t lines, one for each test case.

In each line you must print the elements of the merged list separated by spaces. Example: merged_list = [1,2,3], must print: 1 2 3



Select your language