def solve(): S = input() flg = False T = [] num = [] for s in S[::-1]: if flg: T.append(s) elif s.isnumeric(): num.append(int(s)) else: if num: flg = True le = len(num) car = True for i in range(le): num[i] += 1 if num[i] == 10: num[i] = 0 else: car = False break if car: num.append(1) T += num T.append(s) if not flg and num: le = len(num) n = int("".join(num[::-1])) n += 1 T.append(str(n).zfill(le)) print(*(T[::-1]), sep="") for _ in range(int(input())): solve()