def gcd(x, y): 
   while(y): 
       x, y = y, x % y   
   return x
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    m=max(l)
    print(m,end=' ')
    l.remove(m)
    for i in l:
        if gcd(m,i)==1:
            print(i,end=' ')
            l.remove(i)
            print(*l)