from math import *
from collections import *
for u in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    g=l[-1]
    d=[l[-1]]
    l=l[:-1]
    while(len(l)>0):
        x,y=0,0
        for i in l:
            if(gcd(i,g)>x):
                x=gcd(i,g)
                y=i
        g=gcd(g,x)
        d.append(y)
        l.remove(y)
    print(*d)
