DQUERY showing WA

https://ide.geeksforgeeks.org/QIg6iP7Zcl
Here’s my code for DQUERY using mos. Works fine for all test cases. Please help.
Here’s the problem statement- https://www.spoj.com/problems/DQUERY/