from math import gcd

for _ in range(int(input())):
    n = int(input())
    arr=list(map(int,input().split()))
    arr.sort(reverse=True)
    c=[arr[0]]
    gc=arr[0]
    se=set()
    se.add(0)
    for i in range(1,n):
        ma=0
        for j in range(n):
            if gcd(gc,arr[j])>ma and j not in se:
                ma=gcd(gc,arr[j])
                ans=arr[j]
                k=j
        se.add(k)
        c.append(ans)
        gc=gcd(gc,c[i])
    print(*c)
            

