Unable to get the logic in DECSTR

Problem link: https://www.codechef.com/problems/DECSTR

Hello Friends. I am unable to get any logic for the above question. Please can somebody explain me the logic?? Please help.