'''
Name : Abhi Kaila
User : ak2510
Problem Name : B. Big Vova
Contest : Codeforces Round #669 (Div. 2)
'''

from sys import stdin

def get_int(): return int(stdin.readline())
def get_str(): return stdin.readline().strip()
def get_ints(): return map(int, stdin.readline().strip().split())
def get_array(): return list(map(int, stdin.readline().strip().split()))
def get_array2d(row): return [list(map(int, stdin.readline().strip().split())) for _ in range(row)]

def gcd(num1, num2):
    while num2: num1, num2 = num2, num1 % num2
    return num1


T = get_int()
for _ in range(T):
    N = get_int()
    A = get_array()

    st = max(A)
    A.remove(st)
    print(st, end=" ")

    maxGcd, cnt, val = st, 1, 0
    while cnt < N:
        tGcd, val = 0, 0
        for a in A:
            t = gcd(maxGcd, a)
            if t >= tGcd:
                val = a
                tGcd = t
        print(val, end=" ")

        A.remove(val)
        cnt += 1
        maxGcd = tGcd
    print()