import math
import sys
input=sys.stdin.readline
t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    visit=[0 for _ in range(n)]
    curgcd=max(l)
    res=[curgcd]
    visit[l.index(curgcd)]=1
    for i in range(n-1):
        temp,idx=-1,-1
        for j in range(n):
            if(visit[j]==0 and math.gcd(curgcd,l[j])>temp):
                temp=math.gcd(curgcd,l[j])
                idx=j
        res.append(l[idx])
        curgcd=temp
        visit[idx]=1
    print(*res)