from sys import stdin,stdout
from collections import Counter
for _ in " "*int(stdin.readline()):
    a=int(stdin.readline())
    b=sorted(map(int,stdin.readline().split()))[::-1]
    n=Counter(b)
    n[b[0]]-=1
    z=[b.pop(0)]
    while b:
        while n[z[-1]]:z+=[b.pop(0)];n[z[-1]]-=1
        k=z[-1]//2;f=z[-1]
        ok=1
        for i in range(k,0,-1):
            if f%i==0 and n[i]:
                ok=0
                while n[i]:z+=[i];b.remove(i);n[i]-=1
                break
        if ok:
            q=b[0]
            while n[q]:n[q]-=1;b.remove(q);z.append(q)
    print(*z)