import sys,collections,math
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

for _ in range(inp()):
    n = inp()
    a = inpl()
    a.sort()
    seen = set()
    res = [a[-1]]
    seen.add(n-1)
    ggg = a[-1]
    for _ in range(n-1):
        mx = 0
        ans = -1
        for i in range(n):
            if i in seen: continue
            now = math.gcd(ggg, a[i])
            if now > mx:
                mx = now
                ans = i
        ggg = mx
        res.append(a[ans])
        seen.add(ans)
    print(*res)