from math import *

for _ in range(int(input())):
    n = int(input())
    l = sorted(list(map(int, input().split())))[::-1]
    ans = [l[0]]
    vis = [False]*n
    vis[0] = True
    while True:
        if len(ans) == n:
            break
        temp = 0
        ele = ans[-1] if temp==0 else temp
        temp=0
        candidate = -1
        idx = -1
        for i in range(n):
            if vis[i] == False:
                if gcd(ele, l[i]) > temp:
                    temp = gcd(ele, l[i])
                    candidate = l[i]
                    idx = i
        ans.append(candidate)
        vis[idx] = True
    print(*ans)
