import math

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().strip().split()))
    if(n == 1):
        print(*a)
    else:
        b= []
        k = max(a)
        b.append(k)
        a.remove(k)
        while(a):
            f = - 10**9
            m = 0
            for z in a:
                
                temp = math.gcd(k,z)
                if(temp > f):
                    f = temp
                    m = z
            k = f
            b.append(m)
            a.remove(m)
        print(*b)   
                
