def divisors(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d[::-1]

import sys

input=sys.stdin.readline

for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    M = a[-1]
    a.pop()
    res = [M]
    used = [False]*n
    used[-1] = True

    div = divisors(M)
    for d in div:
        for i in range(n-1):
            if not used[i] and a[i]%d == 0:
                res.append(a[i])
                used[i] = True

    print(*res)
