def gcd(a, b):  
    if a == 0 : 
        return b  
      
    return gcd(b%a, a)

for _ in range(int(input())):
    n=int(input())
    a=sorted([int(i) for i in input().split()])[::-1]
    ck=[1]*n;ck[0]=0
    c=[a[0]];cur=a[0]
    
    while(1):
        boo=False
        ma=0;p=-1
        for i in range(n):
            if(ck[i]):
                g=gcd(a[i],cur)
                if(g>ma):
                    ma=g
                    p=i
                    boo=True
                
        if(not boo ):
            break
        #print(cur,ma,p,boo)
        cur=gcd(a[p],cur)
        ck[p]=0
        c.append(a[p])
        
        
    for i in range(n):
        if(ck[i]):
            c.append(a[i])
    print(*c)
