import math

test = int(input())
for _ in range(test):
    num = int(input())
    arr = list(map(int, input().split()))

    arr.sort()
    mgcd = arr.pop()
    arr.reverse()
    ans = [mgcd]
    for i in range(num-1):
        maxi = 1
        for j in range(len(arr)):
            g = math.gcd(mgcd, arr[j])

            maxi = max(g, maxi)

            if maxi == g:
                mi = j
        mgcd = maxi
        ans.append(arr[mi])
        arr.pop(mi)

    print(*ans)
