import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    b=[1]*n
    b[0]=a[0]
    for i in range(1,n):
        for j in range(i,n):

            t=math.gcd(b[i-1],a[j])

            if t>b[i]:
                b[i]=t
                a[i],a[j]=a[j],a[i]
    print(*a)
