def gcd(a, b):  
    if a == 0 : 
        return b  
      
    return gcd(b%a, a) 
for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    v = []
    for i in range(n):
        v.append(0)
    m = max(l)
    i = l.index(m)
    v[i]=1
    print(m,end=" ")
    g = m
    for j in range(n-1):
        t = 1
        for i in range(n):
            if v[i]==0:
                temp = gcd(g,l[i])
                if temp>=t:
                    k = i
                    t = temp
        g = t
        v[k]=1
        print(l[k],end=" ")
    print()