def f(S): t = str(int(S) + 1) if S[0] != '0': return t return S[:len(S)-len(t)] + t def increment(S): n = len(S) l, r = 0, 0 for i in range(n): if r == 0 and S[n - 1 - i] in '0123456789': r = n - i elif r != 0 and S[n - 1 - i] not in '0123456789': l = n - i if r == 0: return S return S[:l] + f(S[l:r]) + S[r:] T = int(input()) for _ in range(T): S = input() print(increment(S))