Append Linked Lists

Easy

Given two Linked Lists, append second Linked List to end of first Linked List and return the first list.

Example
List 1: 1→3→4→7
List 2: 6→2→5
Result: 1→3→4→7→6→2→5

Testing

Input Format

The first line contains ‘T’ denoting the number of independent test cases.

For each test case the input has three lines:

  • 'n' and 'm', denoting the length of the linked lists.
  • n space-separated integers denoting elements of the first linked list.
  • m space-separated integers denoting elements of the second linked list.

Output Format

For each test case, the output has one line with space-separated integers.

Sample Input

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

Expected Output

1 3 4 7 6 2 5
3 4 5 6

Constraints

1 <= T <= 100

1 <= n, m <= 1000

1 <= element <= 1000

Editorial Link: Editorial