We can use a binary search to locate $q$. The important observation is that the segments in $S$ are ordered left to right. So, given any segment $s_i$ in $S$, we can in constant time determine if $q$ is to the left or right of $s_i$, which in turn determines if we should continue searching among the segments to the left or right of $s_i$. Thus, we can ultimately locate the segment immediately right of $q$ (if it exists) in $O(\log n)$ time.