for s in[*open(0)][2::2]:
 m=0;a=[0]*4**5;s=s.split()
 for x in map(int,s):y=m=max(m,x);a[x]+=1
 a[y]-=1
 for _ in s:
  print(y)
  b=[];c=[];i=1
  while i*i<=m:
   if m%i<1:b+=i,;c+=m//i,
   i+=1
  for x in c+b[::-1]:
   for y in range(x,4**5,x):
    if a[y]:a[y]-=1;m=x;break
   else:continue
   break