def gcd(a,b):
    if(b==0):
        return a
    return gcd(b,a%b)   
for _ in range(int(input())):
    n=int(input())
    data=[int(x) for x in input().split()]
    ans=[max(data)]
    data.remove(ans[0])
    temp=ans[0]
    for q in range(n-1):
        pos=0
        maximum=0
        for w in range(len(data)):
            t=gcd(temp,data[w])
            if(t>=maximum):
                if(t==maximum):
                    #print(data[w])
                    if(data[pos]>data[w]):
                        pos=w
                else:
                    maximum=t
                    pos=w
        ans.append(data[pos])
        temp=maximum
        data.pop(pos)
    for q in ans:
        print(q,end=' ')
    print()
