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

t=int(input())
for x in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    gc=a[0]
    print(a[0],end=' ')
    a.remove(a[0])
    while(len(a)):
        max=0
        for i in a:
            temp=gcd(gc,i)
            if(temp>max):
                max=temp
                ele=i
        gc=max
        print(ele,end=' ')
        a.remove(ele)
    print("\n")