import sys
input = sys.stdin.readline


def gcd(a: int, b: int) -> int:
    while b:
        a, b = b, a % b
    return a


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    a = sorted(a, reverse=True)
    used = [False] * n
    max_, ind = 0, -1
    ans = []
    for i in range(n):
        if max_ < a[i]:
            max_ = a[i]
            ind = i
    ans.append(a[ind])
    used[ind] = True
    
    gcd_ = a[ind]
    for _ in range(n - 1):
        max_ = -1
        ind = -1
        for j in range(n):
            if used[j]:
                continue
            tmp = gcd(gcd_, a[j])
            if max_ < tmp:
                max_ = tmp
                ind = j
        ans.append(a[ind])
        used[ind] = True
        gcd_ = max_

    print(*ans)