import math


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))

    a.sort()
    m = a.pop()
    a.reverse()
    ans = [m]
    for i in range(n-1):
        mg = 1
        for j in range(len(a)):
            g = math.gcd(m, a[j])

            mg = max(g, mg)

            if mg == g:
                index = j
        m = mg
        ans.append(a[index])
        a.pop(index)

    print(*ans)
