from math import gcd 
for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    
    preg=max(arr)
    visit=[0]*n
    visit[arr.index(preg)]=1
    print(preg,end=" ")
    for i in range(n-1):
        maxg=0
        temp=0
        for j in range(n):
            if(visit[j]==0 and maxg<=gcd(preg,arr[j])):
                temp=j
                maxg=gcd(preg,arr[j])
                
        print(arr[temp],end=" ")
        preg=gcd(preg,arr[temp])
        visit[temp]=1
    print()    