Help in infinity chess?

can you guys help with this problem , not getting idea to solve this one?
problem: CodeChef: Practical coding for everyone