from sys import stdin
from math import gcd
inp = lambda : stdin.readline().strip()

t = int(inp())

for _ in range(t):
    n = int(inp())
    a = [int(x) for x in inp().split()]
    ans = [max(a)]
    used = set()
    used.add(a.index(ans[-1]))
    gcdC = ans[-1]
    
    for i in range(n-1):
            maxGCD = -1
            maxInd = -1
            for j in range(n):
                if j not in used and gcd(gcdC,a[j]) > maxGCD:
                    maxGCD =  gcd(gcdC,a[j])
                    maxInd = j
            gcdC = maxGCD
            used.add(maxInd)
            ans.append(a[maxInd])
    print(*ans)