from math import gcd
t = int(input())
for i in range(t):
    n = int(input())
    nums = sorted(map(int, input().split()), reverse=True)
    out = [nums[0]]
    g = nums.pop(0)
    for j in range(n-1):
        # print(nums, n-1-j)
        cp = -1
        cg = -1
        for d in range(n-1-j):
            cur = gcd(g, nums[d])
            if cur > cg:
                cg = cur
                cp = d
        out.append(nums[cp])
        del nums[cp]
        g = cg
    print(' '.join(map(str, out)))
