import sys
if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
    
    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()

RS = raw_input
RI = lambda x=int: map(x,RS().split())
RN = lambda x=int: x(RS())
''' ...................................................................... '''
MX = 10**3+1

def factor(n,p = 0):
    if p: pair = []
    else: fac1,fac2 = [],[]
    
    i = 1
    while i*i<=n:
        if n%i==0:
            j = n/i
            if p: pair.append((i,j))
            else:
                fac1.append(i)
                if i != j: fac2.append(j)
            
        i+=1

    if p: return pair
    else: return fac1+fac2[::-1]    # reverse it
    

for _ in xrange(RN()):
    n = RN()
    arr = RI()

    cnt = [0]*MX
    
    high = arr[0]
    for i in arr:
        cnt[i]+=1
        if i>high: high=i

    ans = [high]
    cnt[high]-=1
    
    while n>1:
        n-=1
        found = 0
        for f in factor(ans[-1])[::-1]:       #reverse
            if cnt[f]>0:
                ans.append(f)
                cnt[f]-=1
                found = 1
                break

        if found==0: break

    for i in xrange(MX):
        tmp = [i]*cnt[i]
        ans.extend(tmp)

    print ' '.join(map(str,ans))
        

    
