Effect of charge exchange reactions on the motion of ions in three-dimensional quadrupole electric fields