import math
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n=int(input())
    ar=list(map(int,input().split()))
    ar.sort(reverse=True)
    ans=[0]
    key={0}
    nu=1
    pre=ar[0]
    while(nu!=n):
        ma=0
        ne=0
        for j in range(n):
            if(not(j in key)):
                gc=math.gcd(pre,ar[j])
                if(gc>ma):
                    ma=gc
                    ne=j
        pre=ma
        ans.append(ne)
        nu+=1
        key.add(ne)
    final=[]
    for i in ans:
        final.append(ar[i])
    print(*final)
        