from math import gcd
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    gcd1=[[] for i in range(10**3+1)]
    a.sort(reverse=True)
    ans=0
    if(n==2 or  n==1):
        print(*a)
        continue
    a1=[a[0]]
    s=set()
    prevk=0
    a1.append(0)
    s.add(0)
    prev=a[0]
    for i in range(n-1):
        prevk=0
        for j in range(n):
                if(j not in s):
                    k=gcd(prev,a[j])
                    if(k>prevk):
                        #print(k)
                        prevk=k
                        km=j
                        a1[-1]=a[j]
        s.add(km)
        prev=prevk
        a1.append(0)
        #print(a1)
    print(*a1[:-1])
