T = int(input()) for i in range(T): S = input() lisS = list(S) num = [str(x) for x in range(10)] numS2 = {i: int(S[i]) for i in range(len(S)) if S[i] in num} if numS2 == {}: print(S) exit() maxi = max(list(numS2.keys())) mini = maxi ss = "" try: while 1: ss = str(numS2[mini]) + ss mini -= 1 except KeyError: if ss != "": max_len = len(ss) print("".join([ S[:mini + 1], str(int(ss) + 1).zfill(max_len), S[maxi + 1:] ]))