def linput():
    return [int(i) for i in input().split()]

def nod(a, b):
    while a != 0 and b != 0:
        if a > b:
            a = a % b
        else:
            b = b % a
    return a + b

qwertyyyyyy =  int(input())
for ______ in range(qwertyyyyyy):
    n = int(input())
    q = linput()
    qans = []
    qans.append(max(q))
    w = max(q)
    q.remove(w)
    ww = -1

    for j in range(n - 1):
        tt = 0
        for i in q:
            t = nod(w, i)
            if t > ww:
                ww = t
                tt = i
        w = ww
        qans.append(tt)
        q.remove(tt)
        ww = -1
    print(*qans)
