ps = {'+' => 1, '-' => 1, '*' => 2, '/' => 2}
gets.to_i
  .times
  .lazy
  .map{ gets.chomp }
  .map {|s| s.scan(/([+\-*\/()]|\d+)/).flatten }
  .map {|tokens|
    ops = []
    tokens.each_with_object([]) {|t, rpn|
      case t
      when /\d+/
        rpn << t
      when '('
        ops << t
      when ')'
        op = nil
        rpn << op until (op = ops.pop) == '('
      else
        p = ps[t]
        rpn << ops.pop until p > (ps[ops.last] || 0)
        ops << t
      end
    }.push(*ops.reverse)
  }
  .map {|rpn|
    rpn.reduce([]) {|s, t|
      case t
      when /\d+/
        s << t.to_i
      else
        r = s.pop
        l = s.pop
        s << l.send(t, r)
        s
      end
    }.first
  }
  .each(&method(:puts))