import sys     
import math as mt
input=sys.stdin.readline
t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    ind=[0]*(n+1)
    l.sort(reverse=True)
    print(l[0],end=" ")
    g=l[0]
    ind[0]=1
    for i in range(n-1):
        i1=0
        maxi=1
        maxval=0
        for j in range(1,n):
            if ind[j]==0:
                x=mt.gcd(l[j],g)
                #print('x ',x,end=" ")
                if maxi<x:
                    maxval=l[j]
                    maxi=x
                    i1=j
                elif maxi==x and maxval<l[j]:
                    maxi=x
                    maxval=l[j]
                    i1=j
        ind[i1]=1
        g=maxi
        #print('ind ',i1,end=" ")          
        print(l[i1],end=" ")
    print()    
        