def gcd(a, b):  
    if a == 0 : 
        return b  
      
    return gcd(b%a, a) 
T=int(input()) 
for t in range(T):
    N=int(input()) 
    A=list(map(int,input().split())) 
    A.sort() 
    A.reverse() 
    B=[]
    C=[]  
    for a in A:
        B.append((gcd(a,A[0]),a)) 
    B.sort() 
    B.reverse()  
    for b in B:
        print(b[1],end=' ') 
    print('')  