import sys

input = sys.stdin.readline

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

t = int(input())

for _ in range(t):
    n = int(input())
    arr = list(map(int, input().split()))
    m = max(arr)
    tmp_m, tmp_gcd, idx = -1, -1, 0
    n_arr = [m]
    arr.remove(m)
    while arr:
        tmp_m, tmp_gcd, idx = 0, 0, 0
        for i in range(len(arr)):
            now_gcd = gcd(m, arr[i])
            now_num = arr[i]
            if now_gcd > tmp_gcd:
                tmp_num = now_num
                tmp_gcd = now_gcd
                idx = i
            elif now_gcd == tmp_gcd and now_num > tmp_num:
                tmp_num = now_num
                idx = i
        n_arr.append(arr[idx])
        arr.remove(arr[idx])
        m = tmp_gcd
    print(*n_arr)