p00109 Smart Calculator
Your task is to write a program which reads an expression and evaluates it.

* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109



Input

The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.

Output

For each datasets, prints the result of calculation.

Example

Input

2
4-2*3=
4*(8+4+3)=


Output

-2
60
```python
from collections import deque

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

n = int(input())
for i in range(n):
    s = input()
    out = []
    ope = deque([])
    for j in range(len(s)):
        inp = s[j]
        if inp == "=":
            while len(ope):
                out.append(ope.pop())
            break
        elif inp.isdecimal():
            if len(out) and s[j - 1].isdecimal():
                tmp = out.pop()
                out.append(tmp*10 + int(inp))
            else:
                out.append(int(inp))
        elif inp == "(":
            ope.append(inp)
        elif inp == ")":
            while True:
                tmp = ope.pop()
                if tmp == "(":
                    break
                out.append(tmp)
        elif priority[inp] == 1:
            while len(ope) and priority[ope[-1]] >= 1:
                tmp = ope.pop()
                out.append(tmp)
            else:
                ope.append(inp)
        elif priority[inp] == 0:
            while len(ope) and priority[ope[-1]] >= 0:
                tmp = ope.pop()
                out.append(tmp)
            else:
                ope.append(inp)
    ans = deque([])
    for k in range(len(out)):
        if out[k] == "+":
            a = ans.pop()
            ans[-1] += a
        elif out[k] == "-":
            a = ans.pop()
            ans[-1] -= a
        elif out[k] == "*":
            a = ans.pop()
            ans[-1] *= a
        elif out[k] == "/":
            a = ans.pop()
            b = ans.pop()
            ans.append(int(b/a))
        else:
            ans.append(out[k])
    print(ans[0])


```