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()))
    # data.sort(reverse=True) # lexical
    
    all_divisors = []
    all_divisors_set = []
    for i in range(n):
        all_divisors.append(sorted(find_all_divisors_of_a_number(data[i]), reverse=True))
        all_divisors_set.append(set(all_divisors[i]))
  
    visited = [False] * n
    maximum_index = -1
    maximum_value = -1
    for i in range(n):
        if data[i] > maximum_value:
            maximum_index = i
            maximum_value = data[i]
    
    print(maximum_value, end=' ')
    visited[maximum_index] = True
    now_set = all_divisors_set[maximum_index]

    for i in range(n - 1):
        now_index = -1
        now_value = -1
        for j in range(n):
            if visited[j]:
                continue
            for k in all_divisors[j]:
                if k in now_set:
                    if k > now_value:
                        now_value = k
                        now_index = j
        maximum_index = now_index
        maximum_value = data[now_index]
        print(maximum_value, end=' ')
        visited[maximum_index] = True
        now_set = now_set & all_divisors_set[maximum_index]
 
    maximum = max(data)
    divisors = set()
    
    print()