


The first line of input contains an integer 'T’ denoting the number of test cases.
The next ‘2*T’ lines represent the ‘T’ test cases.
The first line of each test case contains integers denoting the nodes of the linked list. Each line is guaranteed to have -1 at the end to signify the end of the linked list.
The second line contains an integer ‘x’.
For each test case, print space-separated integers terminated by -1 denote the elements of the given linked lists which are sorted in non-decreasing order.
The output of each test case should be printed in a new line.
1 <= ’T’ <= 50
-1000 <= ’x’ <= 1000
0 <= Length of linked list <= 10000
-1000 <= "data" <= 1000
"data" != -1, 'x' != -1
Where 'T' is the number of test cases. 'x' denotes the given integer and "data" denotes the linked list node value.
Explanation:-
The key idea will be to create two vectors ‘small’ and ‘big’ and store all the values less than ‘x’ in the small vector and values greater than ‘x’ in the big vector. In this way, the relative order will be preserved.
The algorithm is as follows:
Explanation- The key idea is to traverse the linked list and split it into two parts such that the value of nodes less than ‘x’ is in the first part and the value of nodes greater than equal to ‘x’ is in the second part.
The algorithm is as follow:-