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)
    ans=[b[-1]]
    maxi=b[-1]
    b=b[:-1]
    while b:
        maxgcd=0
        x=0
        for k in range(len(b)):
            if gcd(maxi,b[k])>maxgcd:
                x=k
                maxgcd=gcd(maxi,b[k])
        ans.append(b[x])
        maxi=maxgcd
        b.pop(x)
    print(*ans)







