For this Question: Given an array of N elements and a number K. The task is to arrange array elements according to the absolute difference with K, i. e., element having minimum difference comes first and so on.


Note : If two or more elements are at equal distance arrange them in same sequence as in the given array.First line of input contains a single integer T which denotes the number of test cases. Then T test cases follows. First line of test case contains two space separated integers N and K. Second line of each test case contains N space separated integers.

Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= K <= 10^4
1 <= A[i] <= 10^4

Sum of N over all test cases does not exceed 2*10^5For each test case print the given array in the order as described above.Input:
3
5 7
10 5 3 9 2
5 6
1 2 3 4 5
4 5
2 6 8 3

Output:
5 9 10 3 2
5 4 3 2 1
6 3 2 8

Explanation:
Testcase 1: Sorting the numbers accoding to the absolute difference with 7, we have array elements as 5, 9, 10, 3, 2.
Testcase 2: Sorting the numbers according to the absolute difference with 6, we have array elements as 5 4 3 2 1.
Testcase 3: Sorting the numbers according to the absolute difference with 5, we have array elements as 6 3 2 8., I have written this Solution Code: def merge(arr,l,m,h,x):
    n1=m-l+1
    n2=h-m
    L=arr[l:m+1]
    R=arr[m+1:h+1]
    i=j=0
    k=l
    while(i<n1 and j<n2):
        if abs(x-L[i])<=abs(x-R[j]):
            arr[k]=L[i]
            i+=1
        else:
            arr[k]=R[j]
            j+=1
        k+=1
    while(i<n1):
        arr[k]=L[i]
        i+=1
        k+=1
    while(j<n2):
        arr[k]=R[j]
        j+=1
        k+=1

def mergeSort(arr,l,h,k):
    if l<h:
        m=l+(h-l)//2
        mergeSort(arr,l,m,k)
        mergeSort(arr,m+1,h,k)
        merge(arr,l,m,h,k)
if __name__=="__main__":
    t=int(input())
    while t>0:
        n,k=map(int,input().split())
        arr=list(map(int,input().split()))
        mergeSort(arr,0,len(arr)-1,k)
        for i in arr:
            print(i,end=" ")
        print()
        t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?