import math

tests = int(input())
for t in range(tests):
    n = int(input())
    ls = list(map(int, input().split()))
    ls = sorted(ls)[::-1]
    res = [ls[0]]
    curr = ls[0]
    ls = ls[1:]
    while len(res) < n:
        max_item = None
        max_gcd = 0
        new_ls = []
        for item in ls:
            temp = math.gcd(item, curr)
            if temp > max_gcd:
                max_item = item
                max_gcd = temp
        res.append(max_item)
        removed = False
        for item in ls:
            if item == max_item:
                if removed:
                    new_ls.append(item)
                else:
                    removed=True
            else:
                new_ls.append(item)
        ls = new_ls
    print(' '.join(list(map(str,res))))