defdecrypt_string(s: str) -> str: t = [] # 用列表模拟字符串 t 的字符数组 history = [] # 记录每一步操作,方便处理 'Z' 回滚 for i, c inenumerate(s): if c == 'R': t.reverse() history.append('R') # 记录反转操作 elif c == 'Z': if history: last_op = history.pop() if last_op == 'R': t.reverse() # 撤销反转 else: if t: t.pop() # 撤销添加的字符 else: t.append(c) history.append(c) # 记录普通字符添加操作 return''.join(t)
# 读取多组输入 T = int(input()) for _ inrange(T): s = input().strip() result = decrypt_string(s) print(result)