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 num = [] T.append(s) if not flg and 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 num = [] print(*(T[::-1]), sep="") for _ in range(int(input())): solve()