# https://codeforces.com/contest/1407/problem/B
from collections import Counter
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here


def GCD(a, b):
    if not b:
        return a
    return GCD(b, a % b)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int, input().split()))
    arr.sort(reverse=True)
    freq = Counter(arr)
    g = arr[0]
    ans = [str(g)]
    freq[arr[0]] -= 1
    if not freq[arr[0]]:
        freq.pop(arr[0])
    while len(freq):
        g, p = max([[GCD(g, x), x] for x in freq], key=lambda item: item[0])
        ans.append(str(p))
        freq[p] -= 1
        if not freq[p]:
            freq.pop(p)
    print(" ".join(ans))
