import sys
from collections import defaultdict
from math import gcd
input=sys.stdin.readline

for _ in range(int(input())):
    n=int(input())
    lis=list(map(int,input().split()))
    res=[]
    lis.sort(reverse=True)
    res.append(lis[0])
    g=lis[0]
    lis[0]=-1
    for i in range(n-1):
        m=-1
        mi=-1
        for j in range(n):
            if lis[j]!=-1:
                x=gcd(g,lis[j])
                if m<x:
                    m=x
                    mi=j
        res.append(lis[mi])
        g=m
        lis[mi]=-1
    print(*res)

        
    
