

If we have A = [3, 5, 7, 9, 2, 6] and m = 5.
Difference of array elements with m : [2, 0, 2, 4, 3, 1].
Array after rearrangement : [5, 6, 3, 7, 2, 9].
The first line contains a single integer ‘T’ denoting the number of test cases.
The first line of each test contains two integers, ‘N’ - number of elements in the array and ‘m’
The second line of each test case contains ‘N’ space-separated integers that make up ‘A’.
For each test case, you need to print space-separated integers denoting the elements of the re-arranged array.
Print the output of each test case in a separated line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
1 <= m <= 10^5
Where ‘T’ is the number of test cases, ‘N’ is the length of array ‘A’, and ‘m’ is the value given as described in the problem statement.
Algorithm
We can solve this problem by using a multimap.
Multimap is similar to a map with an addition that in multimap, multiple elements can have the same key. Multimap also stores all the keys in sorted order, and if two elements have the same key, then the element inserted first is stored before the second in multimap.
For example if A = [ 2, 5, 9, 3 ] and m =7
Multimap will store values as
2 -> 5
2 -> 9
4 -> 3
5 -> 2
The re-arranged array will be [ 5, 9, 3, 2 ].
Algorithm