def Sort(sub_li,y):
    sub_li.sort(key=lambda x: x[y])
    return sub_li
def gcd(a,b):
    if(b==0):
        return a
    return gcd(b, a%b)
a=int(input())
for j in range(a):
    b=int(input())
    c=[int(x) for x in input().split()]
    z=[]
    y=[]
    for j in range(b):
        z.append(c[j])
    x1=max(c)
    y.append(x1)
    for j in range(b):
        d=[]
        d.append(c[j])
        d.append(gcd(x1,c[j]))
        c[j]=d
    count=-100
    Sort(c,1)
    c.pop()
    for j in range(len(c)):
        for k in range(len(c)):
            c[k][1]=gcd(x1,c[k][1])
        Sort(c,1)
        x1=gcd(x1,c[len(c)-1][1])
        y.append(c[len(c)-1][0])
        c.pop()
    for j in range(b):
        print(y[j],end=" ")
    print()
