from sys import stdin
import math
inp = lambda : stdin.readline().strip()
 
t = int(inp())
for _ in range(t):
    n = int(inp())
    a = [int(x) for x in inp().split()]
    a.sort()
    sett = set({n-1})
    ans = [a[n-1]]
    lastGcd = a[n-1]
    for i in range(n-1):
        maxi = -1
        cur = -1
        maxInd = -1
        for j in range(n-1):
            if j not in sett:
                cur = math.gcd(lastGcd, a[j])
                if maxi < cur:
                    maxi = cur
                    maxInd = j
        lastGcd = maxi
        sett.add(maxInd)
        ans.append(a[maxInd])
    print(*ans)