STRING QUERY - WA

Can somebody check this solution and tell whats wrong in here ?

http://www.codechef.com/viewsolution/2056897

Even if you fix this code you will get TLE.

//