import re

class c:

 def __init__(self,value):self.x=value

 def __str__(self):return str(self.x)

 def __add__(self,value):return c(self.x+value.x)

 def __sub__(self,value):return c(self.x-value.x)

 def __mul__(self,value):return c(self.x*value.x)

 def __truediv__(self,value):return c(int(self.x/value.x))

for i in[0]*int(eval(input())):print((eval(re.sub(r'(\d+)',r'c(\1)',input()[:-1]))))

r={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}

for _ in[0]*int(eval(input())):

 L=[];t=''

 for e in input()[:-1]:

  if e.isdigit():t+=e

  else:

   if t:L+=[t];t=''

   L+=e

 if t:L+=[t]

 P,S=[],[]

 for i in L:

  if"("==i:S+=i

  elif")"==i:

   while"("!=S[-1]:P+=S.pop()

   S.pop()

  elif i in r:

   while S and r[S[-1]]>=r[i]:P+=S.pop()

   S+=i

  else:P+=[i]

 while S:P+=S.pop()

 for x in P:

  if x in'+-*/':t=S.pop();S+=[str(int(eval(S.pop()+x+t)))]

  else:S+=[x]

 print((*S))

import re


class c:
    def __init__(self, value):
        self.x = value

    def __str__(self):
        return str(self.x)

    def __add__(self, value):
        return c(self.x + value.x)

    def __sub__(self, value):
        return c(self.x - value.x)

    def __mul__(self, value):
        return c(self.x * value.x)

    def __truediv__(self, value):
        return c(int(self.x / value.x))


for i in [0] * int(eval(input())):
    print((eval(re.sub(r"(\d+)", r"c(\1)", input()[:-1]))))

r = {"*": 2, "/": 2, "+": 1, "-": 1, "(": 0, ")": 0}
for _ in [0] * int(eval(input())):
    L = []
    t = ""
    for e in input()[:-1]:
        if e.isdigit():
            t += e
        else:
            if t:
                L += [t]
                t = ""
            L += e
    if t:
        L += [t]
    P, S = [], []
    for i in L:
        if "(" == i:
            S += i
        elif ")" == i:
            while "(" != S[-1]:
                P += S.pop()
            S.pop()
        elif i in r:
            while S and r[S[-1]] >= r[i]:
                P += S.pop()
            S += i
        else:
            P += [i]
    while S:
        P += S.pop()
    for x in P:
        if x in "+-*/":
            t = S.pop()
            S += [str(int(eval(S.pop() + x + t)))]
        else:
            S += [x]
    print((*S))

-import re - - -class c: -    def __init__(self, value): -        self.x = value - -    def __str__(self): -        return str(self.x) - -    def __add__(self, value): -        return c(self.x + value.x) - -    def __sub__(self, value): -        return c(self.x - value.x) - -    def __mul__(self, value): -        return c(self.x * value.x) - -    def __truediv__(self, value): -        return c(int(self.x / value.x)) - - -for i in [0] * int(eval(input())): -    print((eval(re.sub(r"(\d+)", r"c(\1)", input()[:-1])))) +r = {"*": 2, "/": 2, "+": 1, "-": 1, "(": 0, ")": 0} +for _ in [0] * int(eval(input())): +    L = [] +    t = "" +    for e in input()[:-1]: +        if e.isdigit(): +            t += e +        else: +            if t: +                L += [t] +                t = "" +            L += e +    if t: +        L += [t] +    P, S = [], [] +    for i in L: +        if "(" == i: +            S += i +        elif ")" == i: +            while "(" != S[-1]: +                P += S.pop() +            S.pop() +        elif i in r: +            while S and r[S[-1]] >= r[i]: +                P += S.pop() +            S += i +        else: +            P += [i] +    while S: +        P += S.pop() +    for x in P: +        if x in "+-*/": +            t = S.pop() +            S += [str(int(eval(S.pop() + x + t)))] +        else: +            S += [x] +    print((*S))