
T = int(input())

#lets = 'abcdefghijklmnopqrstuvwxyz'
#key = {lets[i]:i for i in range(26)}

def prime(n):
  for i in range(2,2+int(n**0.5)):
    if n%i == 0:
      return 0 
  return 1


def gcd(a,b):
  while b:
    a, b = b, a%b
  return a


for t in range(T):
  n = int(input())
  #n,k = map(int,input().split())
  a = list(map(int,input().split()))
  #a = input()
  d = False
  a.sort()
  used = [0]*(n)

  cg = a[n-1]
  cgi = n-1
  for i in range(n):
    used[cgi] = 1
    print(a[cgi],end = ' ')
    ccg = 1
    for j in range(n):
      if not used[j]:
        #print('\n',cg,'_',a[j],gcd(cg,a[j]))
        #print('--',gcd(cg,a[j]),a[j],cg,ccg,'---')
        if gcd(cg,a[j]) >= ccg:
          #print('HERE')
          ccg = gcd(cg,a[j])
          #print(ccg,'h')
          cgi = j
    cg = ccg
    #print(cg,'HERE')
    #if cg == 1:
    #  used[cgi] = 1
    #  d = True
    #  break
  
  #for i in range(n):
  #  if not used[i]:
  #    print(a[i],end='.')
  print()
      


    