######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline
 
# import sys
import heapq 
import copy
import math
import decimal
 
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &    Bitwise AND Operator    10 & 7 = 2
# |    Bitwise OR Operator    10 | 7 = 15
# ^    Bitwise XOR Operator    10 ^ 7 = 13
 
# <<    Bitwise Left Shift operator    10<<2 = 40
# >>    Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
# n = 100
# parent = [-1 for i in range(n)]
# def find(a):
#     if parent[a] == a:
#         return a
#     else:
#         parent[a] = find(parent[a])
    
# def union(a,b):

# def is_same(a,b):


def inp():
    return(int(input()))
def inlt(): 
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def insr2():
    s = input()
    return((s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
############ ---- Input Functions ---- #######End
# #####   
 

ans = 0
def pr_list(a):
    print( *a , sep=" ")

def swap(a,b):
    temp = a
    a = b
    b = temp
    return [ a,b]
    # return [b,a]
def main():
    tests =  inp()
    # tests = 1
    mod = 1000000007
    limit = 10**18
    ans = 0
    stack = []
    hashm = {}
    arr = []
    heapq.heapify(arr) 
        
    for test in range(tests):

        n = inp()
        a = inlt()
        ans = []
        a.sort(reverse = True)
        done  = [0 for i in range(n)]
        ans.append(a[0])
        curr= ans[0]
        done[0] = 1
        def gcd(a,b):
            
            if a>b:
                [a,b] = swap(a,b)
            if b%a == 0:
                return a
            return gcd(b%a,a)
        for i in range(1,n):
            dum = -1*sys.maxsize
            target  = 0
            for j in range(n):
                if done[j] == 0:
                    t = gcd(curr, a[j])
                    if t >dum:
                        dum = t
                        target = j
            done[target] = 1
            ans.append(a[target])
            curr  = gcd(curr,a[target])
        pr_list(ans)



            
                

        


if __name__== "__main__":
    main()
