# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 08/09/2020
from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

tc = ii1()
for _ in range(tc):
    n = ii1()
    arr = sorted(iia(), reverse=True)
    ans = [arr[0]]
    cur_gcd = arr[0]
    seen = set([0])
    while len(seen) < n:
        cur = None
        for i in range(len(arr)):
            if i not in seen:
                temp = gcd(cur_gcd, arr[i])
                if cur == None:
                    cur = [temp, i]
                else:
                    if temp > cur[0]:
                        cur = [temp, i]
                    elif temp == cur[0] and arr[i] > cur[1]:
                        cur = [temp, i]
        ans.append(arr[cur[1]])
        cur_gcd = gcd(cur_gcd, arr[cur[1]])
        seen.add(cur[1])
    print(*ans)
