import math
for _ in range (int(input())):
    n=int(input())
    a=list(map(int, input().split()))
    a.sort(reverse=True)
    b=[a[0]]
    a.remove(a[0])
    g=b[0]
    i=0
    while i<n-1:
        res=0
        val=0
        for j in range(len(a)):
            x=math.gcd(g,a[j])
            if x>=res:
                res=x
                val=a[j]
        b.append(val)
        g=res
        a.remove(val)
        i+=1
    print(*b)