from math import gcd
input=__import__('sys').stdin.readline
for _ in range(int(input())):
    n=int(input())
    s=sorted(map(int,input().split()))
    ans=[s.pop()]
    cg=ans[0]
    s.reverse()
    while s:
        f=[];ind=0
        for i in s:
            f.append((gcd(cg,i),ind));ind+=1
        f.sort()
        cg=f[-1][0]
        ans+=s.pop(f[-1][1]),
    print(*ans)