import math
for ad in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort();l.reverse()
    x=[l[0]]
    gc=l.pop(0)
    high=0;ind=-1
    for i in range(n-1):
        for j in range(n-i-1):
            g=math.gcd(gc,l[j])
            #print(g,high,gc,l[j])
            if  g>high:
                    ind=j
                    high=g
        if ind!=-1:
            y=l.pop(ind)
            x.append(y)
            gc=high
            ind=-1
            high=0
    #print(x)
    x+=l
    for i in x:
        print(i,end=" ")
    print()