from collections import Counter
from math import gcd
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=sorted(a,reverse=True)
    ans = [b[0]]
    maxa =b[0]

    try:
        maxi=max(b)
    except ValueError:
        pass
    b=b[1:]
    for k in range(n-1):
        maxg=1
        maxele=0
        for j in range(len(b)):
            if gcd(b[j],maxi)>=maxg and b[j]<=maxa:
                maxg=gcd(maxi,b[j])
                maxele=b[j]
                o=j
        b[o]=99999999
        maxi=maxg
        ans.append(maxele)
    for j in ans:
        print(j,end=" ")
    print("")