Can not understand why my code gives TLE

I don’t know why my solution is giving TLE.

I think time complexity of my solution is O(QlogN), which should pass the test cases in 3 sec time limit. But I am getting TLE.

Here is link to my submission: CodeChef: Practical coding for everyone