Z-query on spoj

What is wrong with my solution of Z-query.I tested it on many random testcases but i am unable to find where my where my code fails. My code is here.