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

t=int(input())
for _ in range(t):
    n=int(input())
    list1=list(map(int,input().strip().split()))

    x=max(list1)
    print(x,end=" ")
    list1.remove(x)
    
    while(len(list1)!=0):
        y=0
        for val in list1:
            temp=hcf(x,val)
            if temp>y:
                y=temp
                cur=val
        x=y
        print(cur,end=" ")
        list1.remove(cur)
        
    print()
        
