def noda(a,b):
    while (a*b)!=0:
        if a>b:
            a=a%b
        else:
            b=b%a
    return a+b
    

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    a.reverse()
    b=[0]*n
    b[0]=a[0]
    a[0]=0
    dm=b[0]
    for j in range(1,n):
        y=0
        for i in range(n):
            if a[i]!=0:
                x=noda(dm,a[i])
                if x>y:
                    y=x
                    p1=a[i]
                    p2=i
        a[p2]=0
        b[j]=p1
        dm=y

    print(*b)


"""
7
2
2 5
4
1 8 2 3
3
3 8 9
5
64 25 75 100 50
1
42
6
96 128 88 80 52 7
5
2 4 8 16 17
"""
