import math

T = int(input())
for _ in range(T):
    n = int(input())
    x = list(map(int, input().split()))

    m = max(x)
    s = set()
    l = list()
    s.add(m)
    l.append(m)
    for i in range(len(x) - 1):
        gcd = m
        r = list()
        for j in range(len(x)):
            if x[j] not in s:
                v = math.gcd(gcd, x[j])
                r.append(v)
            else:
                r.append(0)
        l.append(x[r.index(max(r))])
        s.add(x[r.index(max(r))])

    st = ''
    for i in l:
        st += str(i) + ' '

    print(st)