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=[]
    while len(a):
        m1=0
        for i in range(len(a)):
            m1=max(m1,gcd(maxx,a[i]))
        for i in range(len(a)):
            if gcd(maxx,a[i])==m1:
                l.append(a[i])
                a.pop(i)
                break
    for i in l:
        print i,
    print
