import copy
N = int(input())
Ans = []
for i in range(N):
    A = int(input())
    B = list(map(int, input().split()))
    T = []
    M = max(B)
    used = [0]*(M+1)
    for j in range(A):
        used[B[j]] += 1
    T.append(M)
    used[M] -= 1
    P = []
    for j in range(M + 1, 0, -1):
        if M % j == 0:
            P.append(j)
    while(True):
        if len(T) == A:
            break
        c = 0
        for j in range(len(P)):
            if c == 1:
                break
            for div in range(P[j], M+1, P[j]):
                if used[div] != 0:
                    c = 1
                    for k in range(used[div]):
                        T.append(div)
                        used[div] -= 1
        L = P.copy()
        for div in L:
            if T[-1] % div != 0:
                P.remove(div)
    Ans.append(T)
for i in Ans:
    for j in i:
        print(j, end =" ")
    print()
