import math
for t in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans=[]
    gcd=a[n-1]
    ans.append(a[n-1])
    a.pop(n-1)
    for j in range(n-1):
        b=[]
        for i in range(len(a)):
            b.append(math.gcd(gcd,a[i]))
        maxindex=b.index(max(b))
        ans.append(a[maxindex])
        gcd=math.gcd(a[maxindex],gcd)
        a.pop(maxindex)
    for i in range(len(ans)):
        print(ans[i],end=" ")
    print()

    