from math import gcd
from collections import Counter
def find_ans(n,s):
    u=max(s)
    ans=[u]
    p=dict(Counter(s))
    qq={}
    qq[u]=1
    q=u
    j=0
    Max=-10
    for oo in range(n-1):    
        for i in range(n):
            if gcd(q,s[i])>Max and (qq.get(s[i],0) < p[s[i]]) :
                Max=gcd(q,s[i])
                j=i
        ans.append(s[j])
        qq[s[j]]=qq.get(s[j],0)+1
        q=Max
        Max=-10
    print(*ans)

for _ in range(int(input())):

    n=int(input())
    s=list(map(int,input().split()))
    find_ans(n,s)
