# coding: utf-8 import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def IAI(LINE): return [ILI() for __ in range(LINE)] def IDI(): return {key: value for key, value in ILI()} def read(): T = II() test = [str(input()) for __ in range(T)] return T, test def RepresentsInt(s): try: int(s) return True except ValueError: return False def solve(T, test): ans = [] for t in test: l_ind = None head_ind = None for ind, char in enumerate(t): if RepresentsInt(char): if head_ind is None: head_ind = ind else: continue else: if head_ind is None: continue else: l_ind = (head_ind, ind - 1) head_ind = None else: if head_ind is not None: l_ind = (head_ind, len(t) - 1) if len(l_ind) is None: ans.append(t) else: front_ind, back_ind = l_ind front_str = "".join(t[:front_ind]) num_str = "".join(t[front_ind:back_ind + 1]) back_str = "".join(t[back_ind + 1:]) len_num = len(num_str) num_leveled = str(int(num_str) + 1) if len_num > len(num_leveled): num_leveled = num_leveled.zfill(len_num) all_joined = front_str + num_leveled + back_str ans.append(all_joined) return ans def main(): params = read() ans = solve(*params) for a in ans: print(a) if __name__ == "__main__": main()