import sys,os,io
from math import gcd
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [0]*T
for t in range(T):
  N = int(input())
  ans[t] = [0]*N
  A = list(map(int, input().split()))
  old_g = max(A)
  ans[t][0] = old_g
  A.remove(old_g)
  for i in range(1,N):
    max_g = 0
    for a in A:
      new_g = gcd(a,old_g)
      if new_g>max_g:
        max_g = new_g
        val = a
    ans[t][i] = val
    A.remove(val)
    old_g = max_g
for a in ans:
  print(*a)