def gcd(x, y): 
    while(y):
        x, y = y, x % y
    return x
for test in range(input()):
    n = input()
    a = map(int,raw_input().split())
    b = [0]*n
    ans = []
    ans.append(max(a))
    b[a.index(max(a))] = 1
    prev = ans[0]
    for i in range(1,n):
        m = 0
        val = 0
        for j in range(n):
            if b[j]==0:
                p = gcd(a[j],prev)
                #print j, p, a[j],ans[i-1]
                if p > m:
                    m = p
                    val = a[j]
        #print i, val, m
        ans.append(val)
        prev = m
        b[a.index(val)] = 1
    for x in ans:
        print x,
    print 
