import math
for _ in range(int(input())):
    n = int(input())
    a = [int(x) for x in input().split()]
    idx = 0
    maxi = 0
    for i in range(n):
        if a[i]>maxi:
            maxi = a[i]
            idx = i
    a.pop(idx)
    b = [maxi]
    n -= 1
    prev_gcd = maxi
    while(n!=0):
        nex = 0
        maxi = 0
        idx = 0
        for i in range(n):
            temp = math.gcd(prev_gcd, a[i])
            if temp>maxi:
                maxi = temp
                nex = a[i]
                idx = i
        prev_gcd = maxi
        b.append(nex)
        a.pop(idx)
        n -= 1
    print(*b)
    
    
