Help in spoj zquery

question link : https://www.spoj.com/problems/ZQUERY/
solution link : https://ideone.com/33kvC5
It is running correctly for my sample test cases but giving WA on spoj. can someone
tell the error in my solution?