from sys import stdin
###############################################################
def iinput(): return int(stdin.readline())
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
###############################################################

from math import gcd

def nextGcd(m, a):
    mx = 0
    next = 0
    for i in range(len(a)):
        if a[i] and gcd(m, a[i]) > mx:
            mx = gcd(m, a[i])
            next = i
    return next


t = iinput()
while t:
    t -= 1
    n = iinput()
    a = linput()
    a.sort(reverse=True)
    seq = [a[0]]
    a[0] = None
    curr = seq[-1]
    while len(seq) < n:
        temp = nextGcd(curr, a)
        seq.append(a[temp])
        a[temp] = None
        curr = gcd(curr, seq[-1])
    print(*seq)



