Test cases not passed in piyush and magical park problem

i have tried this problem but some test cases showing wrong answer. but it is getting same sample output. can u tell me how can i modify the code given below to pass all the test cases ?

please share ur solution in cb ide