import re N = int(input()) ptn = '[0-9]+' for i in range(N): S = str(input()) lst = re.findall(ptn, S) if len(lst) == 0: print(S) else: n1 = lst[len(lst) - 1] n2 = int(n1) + 1 print(S[:S.rindex(n1)] + str(n2).zfill(len(n1)) + S[S.rindex(n1) + len(n1):])