from math import gcd
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    maxi = max(arr)
    ans = [maxi]
    arr.remove(maxi)
    g = maxi
    while arr:
        max_gcd = 0
        val = -1
        for ele in arr:
            if gcd(ele, g) > max_gcd:
                max_gcd = gcd(ele, g)
                val = ele
        ans.append(val)
        arr.remove(val)
        g = max_gcd
    print(*ans)