from math import gcd
for T in range(int(input())):
    n = int(input())
    a = sorted(list(map(int, input().split())), reverse = True)
    g = a[0]
    for i in range(n):
        Max = 0
        ind = i
        for j in range(i, n):
            if gcd(g, a[j]) > Max :
                Max = gcd(g,a[j])
                ind = j
        g = Max
        a[i], a[ind] = a[ind], a[i]
    print(*a)