import math

def find_all_divisors_of_a_number(x):
    result = []
    for i in range(1, int(math.sqrt(x)) + 1):
        if x % i == 0:
            result.append(i)
            if i * i != x:
                result.append(x // i)
    return result

for _ in range(int(input())):
    n = int(input())
    data = list(map(int, input().split()))
    maximum = max(data)
    divisors = set(find_all_divisors_of_a_number(maximum))
    
    data.sort(reverse=True)
    visited = [False] * n
    for i in range(n):
        if data[i] == maximum:
            print(maximum, end=' ')
            visited[i] = True
    for i in range(n):
        if data[i] != maximum:
            if data[i] in divisors:
                print(data[i], end=' ')
                visited[i] = True
                divisors = set(find_all_divisors_of_a_number(data[i]))
    for i in range(n):
        if not visited[i]:
            print(data[i], end=' ')
    print()