from __future__ import print_function, division
from sys import stdin, stdout
from fractions import gcd
# from math import *
from collections import *
from operator import mul
from functools import reduce
from copy import copy

rstr = lambda: stdin.readline().strip()
rstrs = lambda: [str(x) for x in stdin.readline().split()]
rint = lambda: int(stdin.readline())
rints = lambda: [int(x) for x in stdin.readline().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
pr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\n')
out = []

for _ in range(int(input())):
    n, a = rint(), sorted(rints())
    ans = [a.pop()]
    g = ans[-1]

    for i in range(n - 1):
        tem = [0, 0]
        for j in range(len(a)):
            if gcd(g, a[j]) > tem[0]:
                tem = [gcd(g, a[j]), j]

        ans.append(a.pop(tem[1]))

    out.append(' '.join(map(str, ans)))

pr(out, '\n')
