from math import gcd
for _ in range(int(input())):
    N=int(input())
    A=list(map(int,input().split()))
    b=max(A)
    c=max(A)
    ans = [b]
    A.pop(A.index(b))
    for _ in range(N - 1):
        g = 0
        for a in A:
           if gcd(c, a) > g:
              g = gcd(c, a)
              b = a
        c = g
        ans.append(b)
        A.pop(A.index(b))
    print(*ans)