BFS problem: SPOJ

How shall i do the problem JANE on spoj?
i tried by maintaining a queue for all possibilities and every time i pop up the queue, i would check the condition (absolute difference <=D) and in last if positions got swapped i would print that pair.

I got TLE in test case 11. How to remove TLE?

My solution