from math import sqrt
from math import gcd

for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    d = {}
    b = sorted(a,reverse=True)
    for i in a:
        d[i] = d.get(i,0) + 1

    
    ni = b[0]
    ans = []
    
    start = b[0]
    for i in range(n):
        mx = 1
        ag = -1
        for j in b:
            if(d[j] > 0):
                g = gcd(ni,j)
                if(g > mx):
                    mx = g
                    ag = j


        if(ag == -1):
            if(d[start] > 0):
                ans.append(start)
                d[start] -= 1
            start = -1
            for p in b:
                if(d[p] > 0):
                    start = p
                    break
            
        else:
            ni = mx
            if(d[ag] > 0):
                ans.append(ag)
                d[ag] -= 1

        #print('ans - ',ans,' ag-',ag,' mx-',mx,' d-',d)

    for i in d:
        if(d[i] > 0):
            ans += [i]*(d[i])

    print(*ans)