Given an array of integers, denoted as \(A\), and an integer \(K\), your task is to implement a sorting algorithm. The goal is to arrange the elements in \(A\) based on their Hamming Distance from the integer \(K\).
The Hamming Distance is defined as the count of differing bits in the binary representations of two integers.
The sorting should be done in ascending order of Hamming distance, and in case of a tie in Hamming Distances, the elements should be sorted in ascending numerical order.
Input Format:
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
The first line contains \(T\) denoting the number of test cases. \(T\) also specifies the number of times you have to run the solve function on a different set of inputs. For each test case:
- The first line contains the integer \(N\) and \(K\).
- The second line contains the array \(A\) of length \(N\)
Output Format: For each test case, print the answer in a new line.
Constraints:
\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^5 \\ 1 \leq K \leq 10^5 \\ 1 \leq A[i] \leq 10^5\)