# def computeGCD(x, y=1):
#     while (y):
#         x, y = y, x % y
#
#     return x

import math

t = int(input())
while(t):
    t-=1
    n = int(input())
    a = [int(_) for _ in input().split(" ")]
    ans = []
    a.sort()
    b = a[::-1]
    maxx_gcd = b[0]
    # b.pop(0)
    removed_indices = {}
    removed_indices[0] = True
    # curr = math.gcd(60, 48)
    while(len(removed_indices)<len(a)):
        maxx_index = 0
        curr_gcd = maxx_gcd
        maxx_gcd = 1
        for k,v in enumerate(b):
            if k not in removed_indices:
                if math.gcd(v,curr_gcd)>=maxx_gcd:
                    maxx_gcd = math.gcd(v,curr_gcd)
                    maxx_index = k
        removed_indices[maxx_index] = True
        # print(maxx_index, maxx_gcd)
        # curr_gcd = maxx_gcd
    ans = []
    for x in removed_indices:
        ans.append(b[x])
    # print(*removed_indices)
    print(*ans)
    # print(b)

    # print(*ans)