def computeGCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
for _ in range(int(input())):
    n=int(input())
    arr=[int(j) for j in input().split()]
    res=[]
    res.append(max(arr))
    arr.remove(max(arr))

    count=0
    while count<n-1:
        x=computeGCD(res[count],arr[0])
        item=arr[0]
        for i in range(1,len(arr)):
            temp=computeGCD(res[0],arr[i])
            if temp>x:
                x=temp
                item=arr[i]
        res.append(item)
        arr.remove(item)
        count+=1
        # print(res)
    print(*res)

