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