import sys
import math
input = sys.stdin.readline

cases = int(input())
for case in range(cases):
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort(reverse=True)
    c = [a[0]]
    ans = [a[0]]
    cnt = 1
    vis = [False] * len(a)
    vis[0] = True
    while cnt < n:
        gcd = 1
        for i in range(len(a)):
            if not vis[i]:
                gcd = max(math.gcd(a[i], c[-1]), gcd)
        for i in range(len(a)):
            if math.gcd(a[i], c[-1]) == gcd and not vis[i]:
                vis[i] = True
                ans.append(a[i])
                cnt += 1
        c.append(gcd)
    print(*ans)
