from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    ans = []
    ans.append(a[0])
    arr = []
    for i in range(1, n):
        arr.append((gcd(a[0], a[i]), a[i]))
    arr.sort()
    c = 1
    cgcd = a[0]
    while c<n:
        c1, c2 = arr.pop()
        if cgcd%c1 == 0:
            ans.append(c2)
            cgcd = c1
            c += 1
            continue
        else:
            arr.append((gcd(cgcd, c1), c2))
            arr.sort()
            
    print(*ans)