import math
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    m=a[0]
    d=[]
    di=dict()
    for i in range(len(a)):
        if math.gcd(m, a[i])!=1:
            if math.gcd(m, a[i]) not in di:
                di[math.gcd(m, a[i])]=[]
            di[math.gcd(m, a[i])].append(a[i])
        else:
            d.append(a[i])
    for i in sorted(di.keys(),reverse=True):
        print(*sorted(di[i],reverse=True),end=" ")
    for i in d:
        print(i,end=" ")
    print()








