import math
 
 
class Read:
    @staticmethod
    def string():
        return input()
 
    @staticmethod
    def int():
        return int(input())
 
    @staticmethod
    def list(sep=' '):
        return input().split(sep)
 
    @staticmethod
    def list_int(sep=' '):
        return list(map(int, input().split(sep)))
 

def solve():
    n = Read.int()
    a = Read.list_int()
    l = 0
    for i in range(n):
        if a[i] > a[l]:
            l = i
    res = [str(a[l])]
    tmp = {}
    tmp[l] = 1
    t = a[l]
    for i in range(n - 1):
        m = 0
        idx = 0
        for j in range(n):
            if j in tmp:
                continue
            c = math.gcd(t, a[j])
            if c > m:
                m = c
                idx = j
        t = m
        tmp[idx] = 1
        res.append(str(a[idx]))
    print(' '.join(res))


# query_count = 1
query_count = Read.int()
while query_count:
    query_count -= 1
    solve()