# yukicoder import re from collections import deque T = int(input()) for _ in range(T): s = input() C = deque(re.split('\d+', s)) D = re.split("[^][0-9]+", s) for i in range(1, len(D)+1): if D[-i].isdecimal(): N = len(D[-i]) K=int(D[-i])+1 K=str(K) D[-i]=K.zfill(N) break D = deque(D) ans = "" if s[0].isdecimal(): P=[] while C or D: if C: P.append(C.popleft()) if D: P.append(D.popleft()) print("".join(P)) else: P=[] while C or D: if D: P.append(D.popleft()) if C: P.append(C.popleft()) print("".join(P))