import math

t = int(input())

while t > 0:

    n = int(input())
    a = list(map(int, input().split()))
    ans = [max(a)]
    curr_gcd = ans[0]
    while len(ans) < n:
        prev = ans[-1]
        next = -1
        temp_gcd = -float('inf')
        a.remove(prev)
        for item in a:
            if math.gcd(item, curr_gcd) > temp_gcd:
                temp_gcd = math.gcd(item, curr_gcd)
                next = item

        curr_gcd = temp_gcd
        ans.append(next)
    print(*ans)

    t -= 1
