from fractions import gcd
def solve():
    n = int(raw_input())
    a = map(int, raw_input().split())
    a.sort(reverse=True)
    y = a[0]
    b = [y]
    a = a[1:]
    for i in xrange(n - 1):
        p = [(gcd(y, x), -x) for x in a]
        y, x = max(p)
        b.append(-x)
        a.remove(-x)
    for x in b:
        print x,
    print

T = int(raw_input())
for t in xrange(T):
    solve()
