import sys
input=sys.stdin.readline

def gcd(a, b):
    return b if a%b==0 else gcd(b, a%b)

t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    a.sort()
    ans=[a[-1]]
    g=a.pop()
    
    while a:
        b=0; bi=0
        for i in range(len(a)):
            if gcd(g, a[i])>=b:
                b=gcd(g, a[i])
                bi=i
        g=b
        ans.append(a.pop(bi))

    print(*ans)