from math import gcd

for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    a = sorted(a)
    ans = [a[-1]]
    check = a[-1]
    del a[-1]
    while(a):
        mx = -11111
        for i in range(len(a)):
            if(mx<=gcd(check,a[i])):
                mx = gcd(check,a[i])
                store = i
        ans.append(a[store])
        del a[store]
        check = mx
    print(*ans)
