from math import gcd
t = int(input())

for _ in range(t):
    n = int(input())
    #s = stdin.readline().strip('\n')
    a = map(int, input().split())
    a=list(a)
    a.sort(reverse=True)
    ans=[a[0]]
    
    d = {}
    g = a[0]
    for i in range(1,n):
        curg=1
        pos=-1
        for j in range(1,n):
            if(j not in d):
                tmp = gcd(g,a[j])
                if(curg<=tmp):
                    curg=tmp
                    pos=j
        d[pos]=0
        ans.append(a[pos])
        g=curg
        
    print(*ans)