import math
test_case = int(input())
for i in range(test_case):
    n = int(input())
    s = input().split(" ")
    L = [0]*n
    for j in range(n):
        L[j] = int(s[j])
    L.sort()
    L.reverse()

    LL = []

    gcd = L[0]
    LL.append(L[0])
    del L[0]
    while len(L) > 1:
        max_gcd = 1
        max_gcd_item = 0
        for j in range(len(L)):
            if math.gcd(gcd, L[j]) > max_gcd:
                max_gcd = math.gcd(gcd, L[j])
                max_gcd_item = L[j]
        if max_gcd == 1:
            break
        LL.append(max_gcd_item)
        gcd = max_gcd
        L.remove(max_gcd_item)
    s = ''
    for j in (LL):
        s += str(j)
        s += " "
    for j in (L):
        s += str(j)
        s += " "
    print(s[:-1])