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
  p calc[0]
end