
from sys import stdin
import sys
import math

tt = int(stdin.readline())

for loop in range(tt):

    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))

    a.sort()
    ans = [a[-1]]
    now = a[-1]
    del a[-1]
    a.reverse()

    able = [True] * (n-1)

    for i in range(n-1):

        tmp = float("-inf")
        maxind = None
        for j in range(len(a)):

            if not able[j]:
                continue
            X = math.gcd(now,a[j])
            if X > tmp:
                tmp = X
                maxind = j
            if tmp > a[j]:
                break

        able[maxind] = False
        ans.append(a[maxind])
        now = tmp

    print (*ans)