from math import *

for _ in range(int(input())):
    n = int(input())
    l = sorted(list(map(int, input().split())))[::-1]
    ans =[]
    vis = [False]*n
    temp=0
    while True:
        if len(ans) == n:
            break
        idx=-1
        bst=-1
        for i in range(n):
            if vis[i]==False:
                x=gcd(l[i],temp)
                if x>bst:
                    bst=x
                    idx=i
        vis[idx]=True
        ans.append(l[idx])
        temp=bst

    print(*ans)
