def solve(arr, used):
    res = [arr[0]]
    curr_gcd = arr[0]
    used[arr[0]] -= 1
    existing_gcd = set()
    existing_gcd.add(curr_gcd)

    def get_gcd(a) -> int:
        gcd = min(a, curr_gcd)
        while gcd > 1:
            if a % gcd == 0:
                if gcd in existing_gcd or all([True if i % gcd == 0 else False for i in res]):
                    return gcd
            gcd -= 1
        return gcd

    while len(res) < len(arr):
        if curr_gcd == 1:
            for a in arr:
                if used[a] > 0:
                    for _ in range(used[a]):
                        res.append(a)
                        used[a] = 0
            break
        else:
            arr.sort(key=get_gcd, reverse=True)
            for i in arr:
                if used[i] > 0:
                    used[i] -= 1
                    curr_gcd = get_gcd(i)
                    existing_gcd.add(curr_gcd)
                    res.append(i)

    for i, el in enumerate(res):
        if i == len(res) - 1:
            print(el)
        else:
            print(el, end=' ')


t = int(input())
for _ in range(t):
    n = int(input())
    arr = [int(i) for i in input().split()]
    count = {}
    for i in arr:
        if i in count:
            count[i] += 1
        else:
            count[i] = 1
    arr.sort(reverse=True)
    solve(arr, count)
