BFS Shortest path

The sample test case is correct but both test cases are showing wrong answer.

Code