next palindrome

http://ideone.com/KHxMDR

this is my code. please help me identify which test case i’m missing.
its giving me an WA

please help me

For following input

3
10
100
87

Your code output is

22
111
99

All three are wrong.