from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math

# sys.stdin = open('input')

def inp(force_list=False):
    re = map(int, raw_input().split())
    if len(re) == 1 and not force_list:
        return re[0]
    return re

def inst():
    return raw_input().strip()

def gcd(x, y):
   while(y):
       x, y = y, x % y
   return x

mod = 1000000007

def my_main():
    T = inp()
    ans = []
    for _ in range(T):
        n = inp()
        da = inp(True)
        mx = max(da)
        st = defaultdict(int)
        for i in da:
            st[i] += 1
        st[mx] -= 1
        ans = [mx]
        now = mx
        for i in range(n-1):
            tmp_min = 10000
            tmx = 1
            for j in st:
                if st[j] and gcd(mx, j) >= gcd(mx, tmx):
                    tmx = j
            # print i, mx, tmx
            mx = gcd(mx, tmx)
            ans.append(tmx)
            st[tmx] -= 1
        print ' '.join(map(str, ans))

    # print '\n'.join(ans)




my_main()
