import math
from decimal import *
import random

for _ in range(int(input())):
    n = int(input())
    arr = sorted(list(map(int, input().split())),reverse = True)
    ans=  [str(arr[0])]
    pos = 0
    mrk = [0]*n
    mrk[0] = 1 
    fin = False
    fnd =False
    mx =arr[0]
    while( not fin):
        tmp = 1
        fnd = False
        for i in range(1, n):
            val = math.gcd(mx, arr[i])
            if(val>tmp and mrk[i]==0):
                pos = int(i)
                fnd = True
                tmp = int(val)
        if(fnd):
            mrk[pos] =1
            ans.append(str(arr[pos]))
            mx = int(tmp)
        else:
            fin = True
    for i in range(n):
        if(mrk[i]==0):
            ans.append(str(arr[i]))
    print(' '.join(ans))
    
