import math

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

def solve():
    N = getInt()
    A = getInts()
    A.sort()
    ans = []
    ans.append(A.pop())
    curr_gcd = ans[0]
    while A:
        best = 0
        ind = -1
        for j in range(len(A)):
            x = math.gcd(A[j],curr_gcd)
            if x > best:
                best = x
                ind = j
        ans.append(A.pop(ind))
        curr_gcd = best
    print(*ans)
        
T = getInt()
for t in range(T):
    solve()

