import math

tests = int(input())
for t in range(tests):
    n = int(input())
    ls = list(map(int, input().split()))
    ls = sorted(list(ls))[::-1]
    res = [ls[0]]
    curr = ls[0]
    new_ls = []
    removed=False
    for item in ls:
        if item != curr:
            new_ls.append(item)
        else:
            if removed:
                new_ls.append(item)
            else:
                removed=True
    ls = new_ls
    while len(ls)>0:
        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:
                new_ls.append(item)
            else:
                if removed:
                    new_ls.append(item)
                else:
                    removed=True
        ls = new_ls
        curr = max_gcd
    print(' '.join(list(map(str,res))))