Next Palindrome TLE

Problem Statement:

I used the spoj wiki guide to write the code and testing out large values is giving pretty quick results(and correct according to me). However on submission I get TLE.

My Solution:

Would really appreciate some help on pointing out whats wrong, including help on how accurate the code is.