import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda: sys.stdin.buffer.readline().rstrip()

def primeFactors(n): 
    a=[]
    # Print the number of two's that divide n 
    while n % 2 == 0: 
        a.append(2) 
        n = n / 2
          
    # n must be odd at this point 
    # so a skip of 2 ( i = i + 2) can be used 
    for i in range(3,int(math.sqrt(n))+1,2): 
          
        # while i divides n , print i ad divide n 
        while n % i== 0: 
            a.append(i) 
            n = n / i 
              
    # Condition if n is a prime 
    # number greater than 2 
    if n > 2: 
        a.append(n)
    return a


for _ in range(int(input())):
	q=int(input())
	w=sorted(list(map(int,input().split())))
	t=max(w)
	l=[t]
	y=t
	k=0
	w.pop(-1)
	while len(w):
		t=0
		for i in range(len(w)):
			a=math.gcd(y,w[i])
			if a>=t:
				t=a
				k=i
		l.append(w[k])
		y=t
		w.pop(k)
	print(*l)

