Problem:
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.

Sample Input

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

Output for the Sample Input

-2
60

Solution in Ruby (judge verdict: Wrong Answer)

op=[")","/","*","+","-","(","="]
gets.to_i.times do
  l1=gets.chomp.split("")
  st,ops=[],[]
  intflg=false
  l1.each do |item|
    if op.include?(item) then
      if item=="(" then
        ops.push(item)
      elsif item==")" then
        while ops[-1]!="("
          st.push(ops.pop)
        end
        ops.pop
      else
        while ops.size>0 and op.index(ops[-1])<op.index(item)
          st.push(ops.pop)
        end
        ops.push(item)
      end
      intflg=false
    else
      if intflg then st.push((st.pop.to_s+item).to_i)
      else st.push(item.to_i) end
      intflg=true
    end
  end
  st.reverse!
  calc=[]
  while st.size > 0
    case n=st.pop
    when "+" then calc.push(calc.pop+calc.pop)
    when "-" then calc.push(-calc.pop+calc.pop)
    when "*" then calc.push(calc.pop*calc.pop)
    when "/" then calc.push((1.0/calc.pop*calc.pop).floor)
    else calc.push(n) end
  end
  puts calc[0]
end