from math import gcd
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    arr.sort(reverse=True)
    vis = [False for i in range(n)]
    
    ans = [arr[0]]
    vis[0] = True
    cnt = 1

    g = arr[0]

    while cnt!=n:
        temp = []
        for i in range(n):
            if vis[i]==False:
                temp.append([-gcd(arr[i],g),-arr[i]])
        temp.sort()
        cur = -temp[0][1]
        g = gcd(g,cur)
        ans.append(cur)
        cnt+=1
        for i in range(n):
            if arr[i]==cur and vis[i]==False:
                vis[i] = True
                break
    print(*ans)