from math import gcd
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))
    arr.sort(reverse=True)
    ans = [arr[0]]
    visited = [False]*n
    visited[0]=True
    p = arr[0]
    while(len(ans)<n):
        temp,tempPos = 0,-1
        for i in range(n):
            if(not visited[i] and gcd(p,arr[i])>temp):
                temp = gcd(p,arr[i])
                tempPos = i
        visited[tempPos] = True
        ans.append(arr[tempPos])
        p = gcd(p,arr[tempPos])
    print(' '.join(map(str,ans)))
        

