import math
b=[]
def solve(a,mx):
    if len(a)==0:
        return
    for i in range(mx,0,-1):
        if mx%i==0:
            d=[]
            for j in a:
                if j%i==0:
                    d.append(j)
            if len(d)>0:
                for k in d:
                    a.remove(k)
                    b.append(k)

                solve(a,i)
                return
t=int(input())
for _ in range(t):
    n=int(input())
    a= list(map(int,input().split(" ")))
    b=[]
    mx=max(a)
    a.remove(mx)
    b.append(mx)

    solve(a,mx)
    print(*b)
