
object Main extends App{
  import scala.io.StdIn.{readLine}
  type Operator = Option[((Int, Int) ⇒ Int, List[Char])]
  type CharParseResult = Option[(Char, List[Char])]
  type ParseResult = Option[(List[Char], List[Char])]
  type CalResult = Option[(Int, List[Char])]
  type CalMidResult = Option[(Int ⇒ Int, List[Char])]
  for (_ ← 0 until readLine().toInt){
    println(readLine().toList match {
      case value AsExpression '='::Nil ⇒ value
      case _ ⇒ ???
    })
  }
  object AsDigit{
    def unapply(arg: List[Char]):CharParseResult = arg match{
      case h::t if h.isDigit ⇒ Some(h, t)
      case _ ⇒ None
    }
  }
  object AsNumber{
    def unapply(arg: List[Char]):ParseResult = arg match{
      case digit AsDigit (number AsNumber rest) ⇒ Some(digit::number, rest)
      case digit AsDigit rest ⇒ Some(digit::Nil, rest)
      case _ ⇒ None
    }
  }
  object AsParenthesis{
    def unapply(arg: List[Char]): CalResult = arg match{
      case '(':: (result AsExpression ')':: rest)⇒ Some(result, rest)
      case _ ⇒ None
    }
  }
  object AsTerm{
    def unapply(arg: List[Char]):CalResult = arg match{
      case number AsNumber rest ⇒ Some(number.mkString.toInt, rest)
      case value AsParenthesis rest ⇒ Some(value, rest)
      case _ ⇒ None
    }
  }
  object AsHighPriorityOperator{
    def unapply(arg: List[Char]):Operator = arg match{
      case '*'::rest ⇒ Some(_ * _ , rest)
      case '/'::rest ⇒ Some(_ / _, rest)
      case _ ⇒ None
    }
  }
  object AsLowPriorityOperator{
    def unapply(arg: List[Char]):Operator = arg match{
      case '+'::rest ⇒ Some(_ + _, rest)
      case '-'::rest ⇒ Some(_ - _, rest)
      case _ ⇒ None
    }
  }
  implicit class BinomialOperator(val operator:(Int, Int) ⇒ Int){
    def <|(num:Int):Int ⇒ Int = operator(_, num)
  }
  implicit class MonomialOperator(val number:Int){
    def |>(op:Int ⇒ Int):Int = op(number)
  }
  object AsHighPriorityOperation{
    def unapply(arg: List[Char]):CalMidResult = arg match{
      case op AsHighPriorityOperator (term AsTerm (converter AsHighPriorityOperation rest)) ⇒ Some(op <| term andThen converter, rest)
      case op AsHighPriorityOperator (term AsTerm rest) ⇒ Some(op <| term, rest)
      case _ ⇒ None
    }
  }
  object AsHighPriorityPartial{
    def unapply(arg: List[Char]):CalResult = arg match{
      case term AsTerm (converter AsHighPriorityOperation rest) ⇒ Some(term |> converter, rest)
      case term AsTerm rest ⇒ Some(term, rest)
      case _ ⇒ None
    }
  }
  object AsLowPriorityOperation{
    def unapply(arg: List[Char]):CalMidResult = arg match{
      case op AsLowPriorityOperator (partial AsHighPriorityPartial (converter AsLowPriorityOperation rest)) ⇒ Some(op <| partial andThen converter, rest)
      case op AsLowPriorityOperator (partial AsHighPriorityPartial rest) ⇒ Some(op <| partial, rest)
      case _ ⇒ None
    }
  }
  object AsExpression{
    def unapply(arg: List[Char]): CalResult = arg match{
      case left AsHighPriorityPartial (right AsLowPriorityOperation rest) ⇒ Some(left |> right, rest)
      case value AsHighPriorityPartial rest ⇒ Some(value, rest)
      case _ ⇒ None
    }
  }
}
