def gcd(a,b):
    while(b!=0):
        a,b=b,a%b
    return a
t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    l = sorted(l)
    l.reverse()
    a = [l[0]]
    g = l[0]
    mx = -100000
    m = 0
    del l[0]
    for j in range(n-1):
        for i in range(len(l)):
            te = gcd(g,l[i])
            if(te>mx):
                mx = te
                m = i
        a.append(l[m])
        g = mx
        del l[m]
        mx = -1000000
    for i in a:
        print(i,end = " ")
    print()


