import re T = int(input()) S = [] for i in range(T): S.append(input()) for s in S: pattern = r'\d+' iterator = re.finditer(pattern, s) match = [] longest = 0 for i in iterator: if len(i.group()) > longest: match = [] match.append(i) longest = len(i.group()) elif len(i.group()) == longest: match.append(i) if len(match) == 0: print(s) next ans = '' for i in range(len(match)): if i == 0: ans += s[:match[i].start()] ans += ('%0' + str(len(match[i].group())) + 'd') % (int(match[i].group()) + 1) if i == len(match): ans += s[match[i].end():match[i+1].start()] else: ans += s[match[i].end():] print(ans)