t=int(input())
for _ in range(t):
    n=int(input())
    l1=list(map(int,input().split()))
    l1.sort(reverse=True)
    l2,l3=[],[]
    l2.append(l1[0])
    m=l1[0]
    for i in range(1,n):
        if m%l1[i]==0:
            l2.append(l1[i])
        else:
            l3.append(l1[i])
    l3.sort()
    l2+=l3
    for i in range(n-1):
        print(l2[i],end=" ")
    print(l2[n-1])