t = int(input())
import heapq, math
for _ in range(t):
    n = int(input())
    A = list(map(int, input().split()))

    if n == 1:
        print(A[0])
        continue

    A.sort(reverse=True)
    g = A[0]
    used = set()
    ans = []
    for i in range(n):
        M = 0
        id = -1
        for j in range(n):
            temp = math.gcd(g, A[j])
            if temp > M and j not in used:
                id = j
                M = temp
        ans.append(A[id])
        g = math.gcd(g, A[id])
        used.add(id)
    print(*ans)
