# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 21:06:21 2020

@author: n
"""
import math

for i in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    l.sort(reverse=True)
    a=max(l)
    l.remove(a)
    p=[]
    q=[]
    q.append(a)
    p.append(a)
    for k in range(n): 
        b=[]
        for j in l:
            b.append(math.gcd(q[k],j))
            #if (p[k]/j==p[k]//j) or (j/p[k] == j//p[k]):
               # l.remove(j)
               # p.append(j)
               # break
            #elif j==l[-1]:
              #  p.append(j)
                #l.remove(j)
        if len(l)>0:
            t=max(b)
            q.append(t)
            
            w=b.index(t)
            p.append(l[w])
            l.remove(l[w])
    print(*p)