from math import sqrt
def fun(a):
    arr = []
    for i in range (1,a+1):
        if a%i==0:
            arr.append(i)
    return arr
def gcd(a,b): 
    if (b == 0): 
         return a 
    return gcd(b, a%b)
    
for _ in range (int(input())):
    n = int(input())
    a = [int(i) for i in input().split()]
    mi = a.index(max(a))
    ans = [a[mi]]
    fact = fun(a[mi])
    a[mi]=-1
    fact.sort(reverse=True)
    for k in range(n-1):
        ma = 0
        mi = 0
        for i in range (n):
            for j in (fact):
                if a[i]!=-1 and a[i]%j==0:
                    if ma<j:
                        ma = j
                        mi = i
                    break
        new = fun(a[mi])
        for j in fact:
            if j not in new:
                fact.remove(j)
        ans.append(a[mi])
        a[mi]=-1
    print(*ans)