from math import gcd
for _ in range(int(input())):
    n=int(input())
    s=map(int,input().split())
    s=list(s)
    g=max(s)
    ans=[]
    while len(s)!=0:
        MAX=0
        for x in s:
            tmp=gcd(g,x)
            if tmp>MAX:
                MAX=tmp
                candidate=x
        g=MAX
        ans.append(candidate)
        s.remove(candidate)
    print(*ans)