import math as mt
t=int(input())
for i in range(0,t):
    m=int(input())
    arr=list(map(int,input().strip().split()))[:m]
    l2=[]
    l3=[]
    y=max(arr)
    l2.append(y)
    l3.append(y)
    arr.remove(y)
    max1=0
    for jk in range(0,m-1):
        max1=0
        for j in arr:
            gc=mt.gcd(l3[-1],j)
            if(gc>max1):
                max1=gc
                k=j
        
        l3.append(max1)
        l2.append(k)
        arr.remove(k)
        
    print(*l2,sep=" ")
        
        
        
    