# cook your dish here
t=int(input())
for _ in range(t):
    s=input()
    l=[]
    res=''
    for i in s:
        if i=='+' or i=='*' or i=='-' or i=='^' or i=='/' or i=='%':
            l.append(i)
        elif i==')':
            res+=l.pop()
        elif i=='(':
            continue
        else:
            res+=i
    print(res)
        

c9a27e2655db8b70dea14c7b18e01cede2fece8c
<mask token>

<mask token>
for _ in range(t):
    s = input()
    l = []
    res = ''
    for i in s:
        if (i == '+' or i == '*' or i == '-' or i == '^' or i == '/' or i ==
            '%'):
            l.append(i)
        elif i == ')':
            res += l.pop()
        elif i == '(':
            continue
        else:
            res += i
    print(res)

t = int(input())
for _ in range(t):
    s = input()
    l = []
    res = ''
    for i in s:
        if (i == '+' or i == '*' or i == '-' or i == '^' or i == '/' or i ==
            '%'):
            l.append(i)
        elif i == ')':
            res += l.pop()
        elif i == '(':
            continue
        else:
            res += i
    print(res)

# cook your dish here
t=int(input())
for _ in range(t):
    s=input()
    l=[]
    res=''
    for i in s:
        if i=='+' or i=='*' or i=='-' or i=='^' or i=='/' or i=='%':
            l.append(i)
        elif i==')':
            res+=l.pop()
        elif i=='(':
            continue
        else:
            res+=i
    print(res)
        
