You are given a linked list of 'N' nodes where nodes can contain values 0, 1, and 2 only. Your task is to sort the linked list.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains 'N'(number of nodes in the linked list) space-separated integers representing the value of each node. -1 at the end denotes NULL pointer.
For example :
The input 0 1 2 -1 denotes a linked list containing 3 nodes represented as:

For each test case, in a separate line, print the final sorted linked list.
Note :
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 100000
0 <= data <= 2
where ‘T’ is the total number of test cases, 'N' is the total number of nodes in the linked list and ‘data’ is the value of any node of the linked list.
2
0 1 1 2 2 1 1 1 0 1 -1
2 2 2 1 0 -1
0 0 1 1 1 1 1 1 2 2
0 1 2 2 2
For the first test case :
The given linked list is :
0 -> 1 -> 1 -> 2 -> 2 -> 1 -> 1 -> 1 -> 0 -> 1 -> null
Therefore after sorting the list will become :
0 -> 0 -> 1 -> 1 -> 1 -> 1 -> 1 -> 1 -> 2 -> 2 -> null
For the second test case :
The given linked list is :
2 -> 2 -> 2 -> 1 -> 0 -> null
Therefore after sorting the list will become-
0 -> 1 -> 2 -> 2 -> 2 -> null
3
0 0 0 -1
0 1 1 2 2 -1
2 2 2 2 2 0 -1
0 0 0
0 1 1 2 2
0 2 2 2 2 2
Can you sort the list by counting?
The idea is to count the number of zero’s, one’s and two’s and then iterate through the list again from beginning to end and put zero’s, then one’s and then two’s.
O(N), where ‘N’ denotes the number of nodes in the linked list.
We are iterating the linked list once for counting and after that for updating the values in the linked list that takes O(N) time. So, the overall Time Complexity becomes O(N).
O(1).
We are using constant extra space. Hence, the overall Space Complexity is O(1).