from math import gcd
test = int(input())
for q in range(test):
    n = int(input())
    a = list(map(int,input().split()))
    m = 1000000000
    a.sort(reverse=True)
    x = []
    g = a[0]
    x.append(a[0])
    a[0] = 0
    N = n-1
    flag = True
    while N>0 and flag:
        cg = 0
        num = -1
        for i in range(n):
            if a[i]!=0 and gcd(a[i],g)>cg:
                cg = gcd(a[i],g)
                num = i
        x.append(a[num])
        g = cg
        a[num] = 0
        if g==1:
            for i in range(n):
                if a[i]!=0:
                    x.append(a[i])
                flag = False
        N-=1
    for i in range(len(x)):
        if i<len(x)-1:
            print(x[i],end=" ")
        else:
            print(x[i])