#优先级
yxj = {"+":1, "-":1, "*":2, "/": 2}
s = "a+b*(c-d)-e/f"
n = int(input())
for _ in range(n):
s = input()
#存储运算符
fh = [""] * 100
topfh = -1
#存储表达式
bds = [""] * 100
top = -1
for ch in s:
#print(bds, top)
#print(fh, topfh)
if ch.isalnum():
top+=1
bds[top] = ch
elif ch == '(':
topfh += 1
fh[topfh] = ch
elif ch == ')':
while True:
t = fh[topfh]
topfh -= 1
if t == '(':
break
top+=1
bds[top] = t
elif ch in yxj:
if topfh ==-1 or fh[topfh] == '(':
topfh+=1
fh[topfh]=ch
elif yxj[ch] > yxj[fh[topfh]]:
topfh+=1
fh[topfh]=ch
else:
while fh[topfh] != '(' and topfh != -1:
if yxj[fh[topfh]] >= yxj[ch]:
top += 1
bds[top] = fh[topfh]
topfh -= 1
else:
break
topfh += 1
fh[topfh]=ch
while topfh != -1:
top += 1
bds[top] = fh[topfh]
topfh -= 1
#print(bds)
print( ''.join(bds[:top+1]))
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com