import math

t = input()
t = int(t)

def solve(n, arr):
    
    b1 = max(arr)

    used = set()

    ans = [0 for i in range(n)]
    ans[0] = b1
    used.add(n-1)
    seed = b1

    for j in range(n-1):
        max_gcd = 1
        for i in range(n):
            if i in used: 
                continue
            now_gcd = math.gcd(arr[i], seed)
            if now_gcd>=max_gcd:
                max_gcd = now_gcd
                max_ind = i

        used.add(max_ind)
        seed = max_gcd
        ans[j+1] = arr[max_ind]

    print(*ans)
    

for i in range(t):
    n = input()
    n = int(n)
    arr = list(map(int, input().split()))
    arr.sort()

    solve(n, arr)