wa again and again

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

My code is not working for the case in which there is repetion of a string
plz help what can i do to rectify my mistake with this algorithm only

Pls make editorial of this question. i couldnt solve it too.