try:
    from math import gcd
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = [int(i) for i in input().split(' ')]
        m = max(a)
        final = []
        while a:
            sets = max((gcd(m,val),val)for val in a)
            a.remove(sets[1])
            final.append(sets[1])
            m = sets[0]
        print(*final)
except:
    pass