# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 20:34:41 2020

@author: Dark Soul
"""
import math
t=int(input(''))
arr=[]
for i in range(t):
    n=int(input(''))
    arr.append(list(map(int,input().split())))
for i in range(t):
    a=arr[i]
    n=len(a)
    a.sort(reverse=True)
    dp=[]
    dp.append(a[0])
    c=[]
    c.append(a[0])

    a[0]=0
    for k in range(1,n):
        sol=0
        
        for j in range(n):
            if a[j]==0:
                continue
            d=math.gcd(c[k-1],a[j])
            
            
            if d>=sol:
                sol=d
                pos=j
        dp.append(a[pos])
        c.append(math.gcd(c[k-1],dp[k]))
        a[pos]=0
    
        if sol==1:
            break
    for j in range(n):
        if a[j]!=0:
            dp.append(a[j])
        
    print(*dp)