Inversions: Small improvement, solve trivial base case when q==p+1