import math
from collections import defaultdict
from collections import Counter 
import itertools

def gcd(a,b):
    if b == 0:
        return a 
    return gcd(b,a%b)
def solve(A):
    
    n = len(A)
    res = []
    ma = float('-inf')
    k = 0
    A.sort()
    g = A[n-1]
    res.append(A[n-1])
    A[n-1]=-1 
    for i in range(1,n):
        ma = float('-inf')
        k = 0
        for j in range(0,n):
            if A[j]!=-1:
                if gcd(A[j],g) >= ma:
                    k = j 
                    ma = gcd(A[j],g)
        res.append(A[k])
        g = gcd(g,A[k])
        A[k] = -1 
    return res
    
    
t = int(input())
#n = int(input())
while t:
    temp = []
    n = int(input())
    in_ = map(int,input().split(" "))
    for x in in_:
        temp.append(int(x))
    print(*solve(temp))
   
    t-=1 
