MOD = 1000000007
ii = lambda :  int(input())
si = lambda :  input()
dgl = lambda : list(map(int, input()))
f = lambda :   map(int, input().split())
il = lambda :  list(map(int, input().split()))
ls = lambda :  list(input())
from collections import *
for _ in range(ii()):
    cdn=0
    def find_gcd(x, y): 
        while(y): 
           x, y = y, x % y 
        return x 
    n=ii()
    a=il()
    cdn=cdn+1
    a.sort(reverse=True)
    gcd=a[0]
    ans=[a[0]]
    for i in range(0,n):
        mx=0
        lpn=0
        lpn=lpn+1
        for i in range(1,len(a)):
            zpn=0
            mx=max(mx,find_gcd(gcd,a[i]))
        for i in range(1,len(a)):
            spm=0
            ld=find_gcd(gcd,a[i])
            if(ld==mx):
                rpn=0
                ans.append(a[i])
                a[i]=-1
                kdn=0
                gcd=mx
                break
    for i in range(0,n):
        print(ans[i],end=" ")
    print("")
    kls=0