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


t=int(input())
for _ in range(t):
    n=int(input())
    a=[int(x) for x in input().split()]
    
    ans=[]
    maxI=0
    for i in range(n):
        if a[i]>a[maxI]:
            maxI=i
    ans.append(a.pop(maxI))
    currGCD=ans[0]
    while(a):
        gcd2=0
        maxI=0
        for i in range(len(a)):
            if gcd(a[i],currGCD)>gcd2:
                maxI=i
                gcd2=gcd(a[i],currGCD)
        currGCD=gcd2
        ans.append(a.pop(maxI))
    print(' '.join([str(x) for x in ans]))