from math import gcd
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))
    arr.sort()
    visited = [0]*n
    visited[n-1] = 1
    num = arr[-1]
    sequence = [arr[-1]]
    for i in range(n-1):
        index = -1
        gcd1 = -1
        for j in range(n):
            if visited[j]==0:
                if gcd(num,arr[j])>gcd1:
                    gcd1 = gcd(num,arr[j])
                    index = j
        num = gcd1
        visited[index]=1
        sequence.append(arr[index])
    print(*sequence)




# def bfs(graph,src,n):
#     visited = [0]*n
#     queue = [src]
#     visited[src]=1
#     dist = [0]*n
#     while queue:
#         a = queue.pop(0)

#         for i in graph[a]:
#             if visited[i]==0:
#                 visited[i]=1
#                 queue.append(i)
#                 dist[i]=dist[a]+1

#     return dist

# ans = 0
# def dfs(graph,src,dist,visited):
#     global ans
#     visited[src]=1
#     neigh = []
#     for i in graph[src]:
#         if visited[i]==0:
#             dfs(graph,i,dist,visited)
#             dist[src] = max(dist[src],dist[i]+1)
#             neigh.append(i)

#     m1 = 0
#     m2 = 0

#     for i in neigh:
#         if dist[i] >= m1:
#             m2 = m1
#             m1 = dist[i]
#         elif dist[i] > m2:
#             m2 = dist[i]
#     count = 0
#     if m1!=0:
#         count+=1
#     if m2!=0:
#         count+=1
#     ans = max(ans,count+m1+m2)


# for _ in range(int(input())):
#     n,a,b,da,db = map(int,input().split())
    
#     graph = []
#     for i in range(n):
#         graph.append([])

#     for i in range(n-1):
#         x,y = map(int,input().split())

#         graph[x-1].append(y-1)
#         graph[y-1].append(x-1)
    
#     visited = [0]*n
#     dist = [0]*n
#     dfs(graph,0,dist,visited)
#     bob = min(db,ans)

#     d = bfs(graph,a-1,n)
#     #print("ans",ans)
#     #print("badkjbar",d[b-1])
#     if bob > 2*da and d[b-1] > da:
#         print("Bob")
#     else:
#         print("Alice")




    
