import sys
range = xrange
input = raw_input

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

t = int(input())
for _ in range(t):
    n = int(input())
    A = [int(x) for x in input().split()]

    B = []
    g = 0
    while A:
        a = max(A, key = lambda a: gcd(a,g))
        B.append(a)
        g = gcd(a,g)
        A.remove(a)
    print ' '.join(str(b) for b in B)
