from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    # m = a.index(max(a))
    # if(n==1):
    #     print(*a)
    # elif(n==2):
    #     print(max(a[0],a[1]),min(a[0],a[1]))
    # else:
        # con = True
    a.sort(reverse=True)
    g = a[0]
    i = 1
    while i<n:
        jj = 0
        for j in range(i,n):
            if(gcd(g,a[j])>jj):
                jj = gcd(g,a[j])
                ind = j
        # if(jj==1):
        #     con = False
        #     break
        # else:
        a[i],a[ind] = a[ind],a[i]
        g = jj
        i+=1

    print(*a)