why i am getting time limit exceed error

my code works perfectly on my laptop…here it gives the time limt exceed error.here is my code.
http://www.codechef.com/viewsolution/3471554

Because your program is taking more than the allowed amount of time to generate all the answers. Have you tried running an input of 500 cases each having 100,000 word-lines?