Extend the test and query offset outside of the loop