Piyush and magical park

in the sample input ,int last row there # ,so he cant able to move forward but why your given he escape !how?
can you explain please

@Chandra123 hey chandra I would recommend you to see this first