import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
 
for _ in range(int(input())):
    n = int(input())
    arr = sorted(list(map(int, input().split())))
    taken = [0] * n
    res = [arr[-1]]
    taken[-1] = 1
    arr.pop(-1)
    last = res[0]
    for i in range(n - 1):
        mx = 0
        ind = 0
        for g in range(n):
            if taken[g]:
                continue
            bf = math.gcd(arr[g], last)
            if bf > mx:
                mx = bf
                ind = g
        res.append(arr[ind])
        taken[ind] = 1
        last = mx
    print(*res)
