for _ in range(int(input())): S = input()[::-1] for i, s in enumerate(S): if s.isdigit(): x = 0 p = i while p < len(S) and S[p].isdigit(): x += int(S[p]) * pow(10, p - i) p += 1 x += 1 S = S[:i] + ("0" * (p - i - len(str(x))) + str(x))[::-1] + S[p:] break print(S[::-1])