for _ in range(int(input())):
    from math import gcd
    # n,s=map(int, input().split())
    n=int(input())
    a=list(map(int, input().split()))
    s=set()
    c=[]
    a.sort()
    c.append(a[n-1])
    s.add(n-1)
    g=a[n-1]
    for i in range(1,n):
        m=0
        ind=-1
        temp=g
        for j in range(n):
            if j not in s and gcd(g,a[j])>=m:
                ind=j
                m=gcd(g,a[j])
        s.add(ind)
        c.append(a[ind])
        g=gcd(g,a[ind])
    print(*c)
            
    
    