import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    g=a[0]
    for j in range(1,n):
        maxg=0
        maxi=j
        for i in range(j,n):
            x=math.gcd(g,a[i])
            if x>maxg:
                maxg=x
                maxi=i
        g=maxg
        a[maxi],a[j]=a[j],a[maxi]
    for i in a:
        print(i,end=' ')
    print()