def gcd(x,y):
    a = max(x,y)
    b = min(x,y)
    while(a%b!=0):
        w = a%b
        a = b
        b = w

    return(b)

def ans(a, n):
    occupied = [0]*n
    gcds = []
    e = max(a)
    answer = [e]
    gcds.append(e)
    occupied[a.index(e)] = 1
    

    for i in range(1,n):
        temp = 0
        ind = -1
        for j in range(n):
            if gcd(gcds[-1], a[j])>temp and occupied[j]==0:
                temp = gcd(gcds[-1], a[j])
                ind = j
        occupied[ind] = 1
        answer.append(a[ind])
        gcds.append(temp)
    
            
    s = ''
    for i in answer:
        s = s+str(i)+' '

    return(s)

m = int(input())
for i in range(m):
    n = int(input())
    arr = input().split()

    a = []
    for j in arr:
        a.append(int(j))

    print(ans(a, n))