from sys import setrecursionlimit
import threading

def gcdofab(a, b):  
    if a == 0 : 
        return b      
    return gcdofab(b%a, a)

def main():
    test = int(input())
    for _ in range(test):
        n = int(input())
        arr = list(map(int, input().split()))
        # main(n, arr)
        arr.sort()
        visited = [0]*n
        visited[-1] = 1
        ans = [arr.pop()]
        a = ans[0]
        for i in range(1, n):
            cur = [0, 0]
            for j in range(n):
                if visited[j]==0:
                    nc = gcdofab(arr[j], a)
                    if nc>cur[0]:
                        cur = [nc, j]
            a = cur[0]
            j = cur[-1]
            visited[j] = 1
            ans.append(arr[j])
        
        for gg in ans:
            print(gg, end=' ')
        print()

setrecursionlimit(10000)
threading.stack_size(10**8)
t = threading.Thread(target=main)
t.start()
t.join()