import math

for _ in range(int(input())):
    n = int(input())
    s = list(map(int, input().split()))
    s.sort()
    g = s[-1]
    k = 0
    b = [s[n-1]]
    s[-1] = -1
    temp = g
    for i in range(1, n):
        ma =0
        k=0
        for j in range(n):
            if s[j] != -1:
                if math.gcd(s[j], g) >=ma:
                    k =j
                    ma = math.gcd(s[j], g)

        b.append(s[k])
        g = math.gcd(g, s[k])
        s[k] = -1
    print(*b)

