logo AlgoBeat OnlineJudge
登录 注册

#207205. 「Wdcfr-1」Magical Expression

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Nitori is learning postfix expressions. She has a incomplete postfix expression of length . Being a Youkai, she wants to find its magical property.

Her postfix expression contains the Bitwise Or operator (denoted as |), the Bitwise And operator (denoted as &), and numbers 0 and 1. Being incomplete, some operators have not been decided yet and are denoted as ?. She promised that will become a vaild postfix expression after you complete it.

In this problem, the term substring is defined as a continuous segment of . Two substrings are considered different as long as their positions or length differ. So 1?0, 01?0 are all substrings of 01?01?| , but 0101 is not.

Nitori found out that a substring of her expression is magical if and only if the following conditions are met:

  • It is possible to transform it into a valid postfix expression after replacing ? with either & or | .
  • Among these transformations, it is possible to find at least one of them that after applying it, the expression yields , and at least one of them that after applying it, the expression yields .

Your task is to find out the number of magical substrings.

输入格式

The first line contains an integer , the number of test cases.

For each test case, input one integer and an expression in a single line.

输出格式

For each test case, print one integer which is the answer.

样例

样例输入 1

2
3 01?
7 01?01?|

样例输出 1

1
3

数据范围与提示

Constraints

. The sum of of all test cases .