import sys
import os


def changeStdioToFile():
    path = os.path.dirname(os.path.abspath(__file__))
    sys.stdin = open(f'{path}/input.txt', 'r')
    sys.stdout = open(f'{path}/output.txt', 'w')


def gcd(a, b):
    if a == 0: return b
    return gcd(b % a, a)

#changeStdioToFile()
t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    b = []
    a.sort(reverse=True)
    b.append(a[0])
    a.pop(0)
    newGcd = b[-1]
    while a:
        numForMaxGcd = a[0]
        maxGcd = 0
        for num in a:
            curGcd = gcd(newGcd, num)
            if maxGcd < curGcd:
                maxGcd = curGcd
                numForMaxGcd = num 
        b.append(numForMaxGcd)
        a.pop(a.index(numForMaxGcd))
        newGcd = gcd(newGcd, numForMaxGcd)
    print(*b)
    
