"""
T = int(input())
for t in range(T):
    line = "Case #" + str(t+1) + ": "
"""
from math import gcd
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    b = []
    b.append(a[0])
    g = a[0]
    visited = set()
    visited.add(0) 
    while True:
        if len(b) == n:
            break
        best = 0
        best_idx = 0
        for j in range(1, n):
            if j in visited:
                continue
            if best < gcd(a[j], g):
                best = gcd(a[j], g)
                best_idx = j
        b.append(a[best_idx])   
        g = best
        visited.add(best_idx)
    print(*b)         