rewrote to loop over queries, and trajectories