import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
#input = iter(sys.stdin.buffer.read().decode().splitlines())._next_
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

for _ in range(int(input())):
    n = int(input())
    A = alele()
    A.sort()
    Ans = []
    Ans.append(A.pop())
    gc = Ans[0]
    while A:
        m=-1;y = -1
        for i in A:
            x = math.gcd(i,gc)
            if x > m:
                m = x
                y = i
        Ans.append(y)
        A.remove(y)
        gc = math.gcd(y,gc)
        if m == 1:
            break
    Ans += A
    print(*Ans)
