import math
for t in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    b = [max(a)]
    a.remove(max(a))
    temp = b[0]
    while len(a) > 0:
        maxi = 0
        add = 0
        for i in range(len(a)):
            if a[i] != b[-1] and math.gcd(temp, a[i]) > maxi:
                maxi = math.gcd(temp, a[i])
                add = i
        b.append(a.pop(add))
        temp = maxi
    print(*b)