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

for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    arr.sort(reverse=True)
    b=[0]*n
    b[0]=arr[0]
    prev=b[0]
    vis=[False]*n
    vis[0]=True
    for i in range(1,n):
        maxGcd,idx=-1,-1
        for j in range(n):
            if(vis[j]):
                continue
            curr=gcd(prev,arr[j])
            if curr>maxGcd:
                maxGcd=curr
                idx=j
        b[i]=arr[idx]
        vis[idx]=True
        prev=maxGcd
    for i in b:
        print(i,end=" ")
    print()
        