def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)

l=[]
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    s=[]
    a.sort()
    s.append(str(a[-1]))
    a=a[::-1]
    t=a[0]
    for i in range(n):
        item=0
        gitem=0
        for j in range(1,n-i):
            if gitem<gcd(t,a[j]):
                item=a[j]
                gitem=gcd(t,a[j])
        s.append(str(item))
        t=gcd(t,item)
        try:
            a.remove(item)
        except:
            None
    l.append(" ".join(s[:n]))
for i in l:
    print(i)


