def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
for _ in range(input()):
    n=input()
    a=[int(i) for i  in raw_input().split()]
    maxx=max(a)
    l=[[gcd(i,maxx),i] for i in a]
    l.sort()
    l=l[::-1]
    nl=[];n=[l[0][1]]
    for i in range(len(l)-1):
        if l[i][0]==l[i+1][0]:
            n.append(l[i+1][1])
        else:
            n.sort()
            for j in n:
                nl.append(j)
            n=[l[i+1][1]]
    n.sort()
    nl+=n
    for i in nl:
        print i,
    print
