Why my solution gives wrong answer for all test cases . It will run on all small cases,

https://ide.geeksforgeeks.org/OwROjEPOzf

Hey Perul
You have a loop for processing Q queries in the end while there is only one query for a testcase. Try removing the Q query loop.