
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)

    while len(l) > 0:
        tlen = len(l)
        maxgcd = gcd(max(m, l[0]), min(m, l[0]))
        maxt = l[0]
        ind = 0

        for i in range(tlen):

            g = gcd(max(m, l[i]), min(m, l[i]))

            if g > maxgcd:
                maxgcd = g
                maxt = l[i]
                ind = i
        
        if maxgcd == 1:
            for i in range(tlen):
                print l[0],
                l.pop(0)

        else:
            print maxt,
            m = maxt
            l.pop(ind)

    print
