'''
Name : Jaymeet Mehta
codeforces id :mj_13
Problem : 
'''
from sys import stdin,stdout
from math import gcd
test=int(stdin.readline())
for _ in range(test):
    n=int(stdin.readline())
    a = [int(x) for x in stdin.readline().split()]
    a.sort(reverse=True)
    b=[max(a)]
    gg=[max(a)]
    ma,mi=0,0
    cnt=1
    s=[False for i in range(n)]
    s[0]=True
    while(cnt<n):
        ma,mi=0,0
        for i in range(n-1,-1,-1):
            if not s[i]:
                g=gcd(gg[-1],a[i])
                if g>ma:
                    ma=g
                    mi=i
        gg.append(ma)
        b.append(a[mi])
        cnt+=1
        s[mi]=True
    print(*b)