# cook your dish here
from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()

    
for _ in range(int(I1())):
    n=int(I1())
    a=list(I())
    m=max(a)
    ind=a.index(m)
    l=[m]
    a[ind]=-1
    g=l[0]
    for i in range(1,n):
        c=0
        m=-1 
        for j in range(n):
            if a[j]==-1:
                continue
            else:
                d=math.gcd(g,a[j])
                if d>c :
                    c=d 
                    m=j 
        l.append(a[m])
        a[m]=-1
        g=c 
    for x in l:
        print(x,end=" ")
    print()
                
    
     

    
        
    
    