from sys import *
from math import *
t=int(stdin.readline())
for _ in range(t):
    n=int(stdin.readline())
    a = list(map(int, stdin.readline().split()))
    a.sort()
    a=a[::-1]
    b=[a[0]]
    x=a[0]
    i=1
    c=[0]*n
    c[0]=1
    while i<n:
        y = 1
        for j in range(n-1,0,-1):
            m=gcd(x,a[j])
            if m>=y and c[j]==0:
                i=j
                y=m
        x=y
        b.append(a[i])
        c[i]=1
        i+=1
    for i in range(n):
        if a[i] not in b:
            b.append(a[i])
    print(*b)
