T = int(input()) lsT = [input() for i in range(T)] for i in range(T): f1 = False f2 = False t = lsT[i] 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() num.reverse() a.reverse() if not num: print(*b,sep='') else: if num[0] == '0': nnum = int(''.join(num)) nnum += 1 c = '0'*(len(num)-len(str(nnum)))+str(nnum) else: nnum = int(''.join(num)) nnum += 1 c = str(nnum) print(''.join(a)+c+''.join(b))