def hcfnaive(a,b): 
    if(b==0): 
        return a 
    else: 
        return hcfnaive(b,a%b) 

    
for _ in range(int(input())):
    
    c = int(input())
    a = list(map(int,input().split()))
    b = a
    b.sort()
    ans=[]
    ans.append(b[c-1])
    curr_gcd = b[c-1]
    b.pop(c-1)
    while(len(ans)!=c):
        fgcd=-1
        for i in range(len(b)):
            poi =hcfnaive(curr_gcd,b[i])
            
            if(poi>fgcd):
                fgcd= poi
                high = i
        ans.append(b[high])
        b.pop(high)
        curr_gcd = fgcd
    for elem in ans:
        print(elem ,end =" ")