GERALD07 help!

This problem:

asks for finding connected components over a range and queries, Here is what I tried:
https://www.codechef.com/viewsolution/30570152
It gives WA and I cant figure out the mistake, also the editorial suggests sqrt method and link cut tree despite this being a simple dfs problem. Came across this problem while reading this article:
https://cp-algorithms.com/graph/search-for-connected-components.html

Hello?