import math
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ans = [max(a)]
    a.remove(ans[0])
    n -= 1
    gcdu = ans[0]
    while(n > 0):
        m = 1
        mi = 0
        for i in range(n):
            k = math.gcd(gcdu, a[i])
            if(k > m):
                m = k
                mi = i
        gcdu = m   
        ans.append(a[mi])        
        a.remove(a[mi])
        n -= 1
    print(*ans)    