Sample Explanation
In Sample Case #1, only the starting position is needed.

In Sample Case #2, notice that although a shorter path exists, the path does not need to be of minimal length, as long as it uses no more than 500 positions.

The following image depicts our solution to Sample Case #3:

Limits
Test set 1 (3 Pts, Visible Verdict)
Test set 2 (11 Pts, Visible Verdict)
Test set 3 (21 Pts, Hidden Verdict)