from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
# sys.setrecursionlimit(10**6)
#------------------------------------------------------------------

from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = list(mapi())
    a.sort(reverse=True)
    res = [a[0]]
    a[0] = -1
    for i in range(n-1):
        mx = 0
        idx = -1
        for j in range(n):
            if a[j]!=-1 and gcd(a[j],res[i])>mx:
                mx = gcd(a[j],res[i])
                idx = j
        res.append(a[idx])
        a[idx] = -1
    print(*res)
