
def gcd(a,b):
    if b == 0:
        return a
    
    return gcd(b, a%b)

T = input()

for t in range(T):
    N = input()
    
    l = list(int(i) for i in raw_input().split())

    l.sort()

    m = l[N-1]

    print m,

    l.pop(N-1)

    redOn = 1

    while len(l) > 0:
        tlen = len(l)
        maxgcd = 1
        t = l[0]
        ind = 0

        for i in range(tlen):

            g = gcd(m, l[i])

            if g > maxgcd:
                maxgcd = g
                t = l[i]
                ind = i
        
        print t,
        m = t
        l.pop(ind)

    print
