def parse tokens
  case t = tokens.shift
  when /\d+/
    parse_with_left_expr t, tokens
  when '('
    pos = tokens.index(')')
    parse_with_left_expr(parse(tokens[0..pos - 1]), tokens[pos + 1..-1])
  else
    raise t.to_s
  end
end

def parse_with_left_expr left, tokens
    return [left] if tokens.empty?
    case op = tokens.shift
    when '+', '-'
      [left, parse(tokens), op]
    when '*', '/'
      case right = tokens.first
      when /\d+/
        tokens.shift
        parse_with_left_expr [left, right, op], tokens
      when '('
        [left, parse(tokens), op]
      else
        raise right.to_s
      end
    else
      raise op.to_s
    end
end

gets.to_i
  .times
  .lazy
  .map{ gets.chomp }
  .map {|s| s.scan(/([+\-*\/()]|\d+)/).flatten }
  .map(&method(:parse))
  .map(&:flatten)
  .map {|tokens|
    tokens.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))