# from bisect import bisect_left
TC = int(input())


def gcd(a, b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a


for tc in range(TC):
    N = int(input())
    A = list(map(int, input().split()))

    M = {}
    maxA = A[0]
    for a in A:
        M[a] = M.setdefault(a, 0) + 1
        maxA = max(maxA, a)

    # print(M,maxA)

    result = []
    for _ in range(M.pop(maxA)):
        result.append(maxA)

    g = result[-1]
    while M:
        mx = 0
        vx = 0
        for i in M:
            t = gcd(g, i)
            if t > mx:
                mx = t
                vx = i
        g = mx
        for _ in range(M.pop(vx)):
            result.append(vx)

    for r in result:
        print(r,end=' ')
    print()
