import math 
for _ in range(int(input())):
    n = int(input())
    lst = list(map(int, input().split()))
    lst.sort(reverse=True)
    ans = [lst[0]]
    num = lst[0]
    lst.pop(0)
    for i in range(n-1):
        m = len(lst)
        number = -1
        temp = -1
        for j in range(m):   
            if math.gcd(num, lst[j])>temp:
                temp = math.gcd(num, lst[j])
                number = j
        ans.append(lst[number])
        lst.pop(number)
        num = temp
    print(*ans)


            