T = int(input()) for i in range(T): f1 = False f2 = False t = input() n = len(t) b = [] num = [] a = [] for j in range(n-1,-1,-1): if not f2: if f1 == False and t[j].isnumeric(): num.append(t[j]) f1 = True elif f1 == False and not t[j].isnumeric(): b.append(t[j]) elif f1 and t[j].isnumeric(): num.append(t[j]) else: a.append(t[j]) f2 = True else: a.append(t[j]) b.reverse() a.reverse() if not num: print(*b,sep='') else: c = [] f = True for s in num: if f and s=='9': c.append('0') continue elif f: c.append(str(int(s)+1)) f = False else: c.append(s) if f: c.append('1') c.reverse() ans = a+c+b print(''.join(ans))