from math import gcd
def main():
    for _ in range(int(input())):
        n=int(input())
        a=list(map(int,input().split()))
        l=[max(a)]
        a.remove(l[-1])
        s=l[-1]
        while(a):
            m=-1
            ans=-1
            for j in range(len(a)):
                if(gcd(a[j],s)>m):
                    m=gcd(a[j],s)
                    ans=a[j]
            s=m
            l.append(ans)
            a.remove(ans)
        print(*l)
        
main()