can anyone explain why i am getting wrong answer for MAXDISTKT

`t=int(input())
while t>0:
   n=int(input())
    arr=list(map(int,input().strip().split()))
    c=[]
    ans=[]
    for i in range(len(arr)):
        j=1
        while True:
            if arr[i]-j not in ans:
                ans.append(arr[i]-j)
                break
            else:
                j+=1
            if j>arr[i]:
                ans.append(arr[i])
                break

    print(" ".join(map(str,ans)))
    t-=1`