from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    b = a[0:1]
    g = b[0]
    a = a[1:]
    while a:
        q = max(a, key= lambda x: gcd(x, g))
        g = gcd(q, g)
        a.remove(q)
        b.append(q)
    print(' '.join(str(x) for x in b))