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