import re N = int(input()) ptn = '[0-9]+' for i in range(N): S = str(input()) o = re.search(ptn, S[::-1]) if o == None: print(S) else: num = int(o.group()[::-1]) + 1 l = o.end() - o.start() if o.start() == 0: print(S[: - o.end()] + str(num).zfill(l)) else: print(S[: - o.end()] + str(num).zfill(l) + S[-o.start():])