import math,sys
input=sys.stdin.readline

T=int(input())
for _ in range(T):
    #n,m=map(int,input().split())
    n=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    B=[A[0]]

    val=A[0]
    vis=[0 for i in range(n)]
    vis[0]=1
    for i in range(1,n):
        ind=i
        j=0
        while(j<n and vis[j]!=0):
            j=j+1

        val1=math.gcd(val,A[j])
        ind=j
        k=j
        for j in range(k+1,n):
            if (vis[j]==0):
                v1=math.gcd(val,A[j])
                if (v1>=val1):
                    val1=v1
                    ind=j

        vis[ind]=1
        val=val1
        B.append(A[ind])

    print(*B)
                
        
        
