WA in NEXTNUM(rank of a number)

can anyone tell me for what testcase my code is giving WA…
link…http://www.codechef.com/viewsolution/2998892

You can ask it in the editorial of the problem here : http://discuss.codechef.com/questions/29663/nextnum-editorial