import math
for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    m = max(l)
    g = m
    p = [m]
    visited = set()
    d = l.index(m)
    visited.add(d)
    j = 0
    #print(visited)
    while j < len(l)-1:
        i = 0
        a = -1
        r = -1
        while (i < len(l)):
            if i not in visited:
                s = math.gcd(l[i], g)
                if s >= a:
                    a = s
                    r = i

            i = i + 1

        j = j+1
        g = a
        visited.add(r)
        p.append(l[r])


    print(*p)