Passing sample test case but further are failing

ques link- https://codeforces.com/problemset/problem/632/C

code link-

passing all sample but hidden failing
please help

Your logic is wrong.
You need to make the lexicographically smallest string.
A string of greater length might be lexicographically smaller than one of smaller length eg. “abc” is smaller than “z”.
So, think of a different logic.