def mii():
    return map(int, input().split())

def gcd(x, y): 
    while(y): 
        x, y = y, x % y 
    return x 

for _ in range(int(input())):
    n = int(input())
    a = list(mii())
    ma = -1e10
    mi = -1
    for i in range(n):
        if a[i]>ma:
            ma = a[i]
            mi = i
    picked = [0]*n
    print (ma, end = ' ')
    picked[mi] = 1
    for i in range(n-1):
        mag = -1
        magi = -1
        for j in range(n):
            if picked[j]:
                continue
            g = gcd(ma, a[j])
            if g>mag:
                mag = g
                magi = j
        print (a[magi], end = ' ')
        picked[magi]=1
        ma = mag
    print()

    