WA in "Encoding" (Problem Code: ENCODING)

https://www.codechef.com/viewsolution/29188747

Is logic correct or is the problem in modular arithmetic? I saw editorial but it is written in alien language :sweat_smile: