from sys import stdin,stdout
import math 
from collections import Counter,deque
L=lambda:list(map(int, stdin.readline().strip().split()))
M=lambda:map(int, stdin.readline().strip().split())
I=lambda:int(stdin.readline().strip())
S=lambda:stdin.readline().strip()
C=lambda:stdin.readline().strip().split()
mod=1000000007
def pr(a):print(" ".join(list(map(str,a))))
#______________________-------------------------------_____________________#

def solve():
    n=I()
    a=L()
    a.sort()
    b=[a[-1]]
    a.pop()
    bo=[0]*n
    bo[-1]=1
    g=b[0]
    while n>len(b):
        m=0
        ind=0
        for i in range(n):
            if bo[i]==0:
                k=math.gcd(g,a[i])
                if k>m:
                    ind=i
                    m=k
        b+=[a[ind]]
        bo[ind]=1
        g=m
    pr(b)
for _ in range(I()):
    solve()

