# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 09:27:51 2020

@author: Nihkv
"""
import math
t = int(input())
for i in range(t):
    n,a=int(input()),list(map(int,input().split()))
    max_a=max(a)
    b=math.gcd(0,max_a)
    a.remove(max_a)
    print(b,end=" ")
    for i in range(n-1):
        l=[]
        for j in range(len(a)):
            l.append(math.gcd(b,a[j]))
        b=max(l)
        ind=l.index(b)
        nomaxgcd=a[ind]
        print(nomaxgcd,end=" ")
        a.remove(nomaxgcd)
    
        
