import sys
from math import gcd
t = int(sys.stdin.readline().strip())

for i in range(t):
    p = []
    n = int(sys.stdin.readline().strip())
    arr = list(map(int, sys.stdin.readline().split()))
    m = 0
    s = set(arr)
    for j in s:
        m = max(j, m)
    s.remove(m)
    p.append(m)
    while len(s) > 0:
        k = 0
        d = 0
        for j in s:
            if k <= gcd(j, p[len(p)-1]):
                k = gcd(j, p[len(p)-1])
                d = j
        p.append(d)
        s.remove(d)
    for h in p:
        print(h, end=' ')
    print('')


