from sys import *
from math import gcd
t = int(stdin.readline().strip())
for k in range(t):
    n = int(stdin.readline().strip())
    a = list(map(int, stdin.readline().split()))
    a.sort(reverse = True)
    currentgcd = a[0]
    start = 1
    for i in range(1,n):
        bestgcd = 0;
        index = -1
        for j in range(i, n):
            guess = gcd(currentgcd, a[j])
            if currentgcd == guess:
                index = j
                break
            if bestgcd < gcd(currentgcd, a[j]):
                index = j
                bestgcd = gcd(currentgcd, a[j])
        a[i], a[index] = a[index], a[i]
        currentgcd = gcd(currentgcd, a[i])

        if currentgcd == 1:
            break
    print(" ".join(map(str, a)))
