import math
from collections import deque
from collections import defaultdict

t = int(input())
while t>0:
    t-=1
    n = int(input())
    arr = list(map(int,input().strip().split(" ")))
    arr.sort(reverse=True)
    
    ans = []
    m = {}
    m[0] = 1
    mx = arr[0]
    ans.append(mx)
    gd = mx
    
    for i in range(n):
        mxx = 0
        mxi = -1
        for j in range(n):
            if m.get(j) is not None:
                continue
            
            k = math.gcd(gd,arr[j])
            if k > mxx:
                mxx = k
                mxi = j
                
        if mxi != -1:
            ans.append(arr[mxi])
            m[mxi] = 1
            gd = math.gcd(gd,arr[mxi])
    
    for i in ans:
        print(i, end=" ")
    print()