You have been given two singly linked lists of length 'N1' and 'N2' respectively. Your task is to modify them by interweaving alternate nodes of the two linked lists. If one list is smaller than the other, complete the process using another linked list.
The first line of input contains an integer 'T' representing the number of Test cases.
The next '2*T' lines denote the 'T' test cases. Each test case consists of two lines.
The first line of each test case contains the first linked list separated by space and terminated by -1.
The second line of each test case contains a second linked list separated by space and terminated by -1.
Output Format :
For each test case, print two lines denoting a single space-separated modified linked list by interweaving alternate nodes of the two linked lists.
The output of each test case will be printed in a separate line.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
The return type is a vector/list of Node*, hence you need to push the head of the first and then second modified linked lists and return the vector/list.
1 <= T <= 10
0 <= N1 <= 10^4
0 <= N2 <= 10^4
-10^9 <= data <= 10^9 and data != -1
Time Limit : 1 sec
3
1 2 3 4 5 -1
6 7 8 9 10 -1
-1
3 4 5 7 -1
5 4 3 7 9 -1
4 3 -1
1 7 3 9 5
6 2 8 4 10
4 7
3 5
5 3 3 9
4 4 7
Here we have 3 test cases, hence there are 3 pairs of linked lists.

Test Case 1: Here we connect alternate nodes of linked list 1 and linked list 2. The yellow link in the above diagram shows the modified linking of linked list 1, similarly, the green link shows the modified linking of linked list 2.

Test Case 2: As the first linked list is of length zero, we need to use the second linked list for the process. Hence first two alternate nodes of linked list 2 would be modified linked list 2 and the remaining alternate nodes would become modified linked list 1. The yellow link in the above diagram shows the modified linking of linked list 1, similarly, the green link shows the modified linking of linked list 2.

Test Case 3: Here the linked list 2 is shorter than linked list 1, hence once we encounter NULL in linked list 2, we would use alternate nodes of linked list 1. The yellow link in the above diagram shows the modified linking of linked list 1, similarly, the green link shows the modified linking of linked list 2.
Traverse iteratively through both the linked list and merge alternate nodes between them.
O(N1 + N2), where ‘N1’ denotes the length of the linked list 1 and ‘N2’ denotes the length of linked list 2.
We are iteratively traversing simultaneously through the linked lists of lengths ‘N1’ and ‘N2’. Hence, the overall time complexity will be O(N1 + N2).
O(1)
We are not using any extra space. Hence, the overall space complexity will be O(1).