You have finally reached the treasure! Of course, it is a string $$$s$$$ of length $$$n=2^k$$$, consisting of brackets.
To be straightforward — cat Persik$$$\text{}^\dagger$$$ loves bracket sequences and powers of two!
Persik plays with the string $$$s$$$ — several times (possibly zero) he divides it into parts and assembles it back.
In one step, the following occurs:
The sequence is divided into blocks of length $$$m = 2^x$$$ $$$(x \ge 1)$$$, each block is split into two halves, and the halves within the block are swapped.
Example:
$$$x = 2, m = 4, s = (()) \Rightarrow |((\cdot))| \Rightarrow |))\cdot((| \Rightarrow ))(($$$
$$$x = 2, m = 4, s = ((()))() \Rightarrow |((\cdot()|))\cdot()| \Rightarrow |()\cdot((|()\cdot))| \Rightarrow ()((()))$$$
$$$x = 1, m = 2, s = ((()))() \Rightarrow |(\cdot(|(\cdot)|)\cdot)|(\cdot)| \Rightarrow |(\cdot(|)\cdot(|)\cdot)|)\cdot(| \Rightarrow (()()))($$$
We are interested in when Persik will get tired of playing (i.e., when he gets bored of changing the original string) — to do this, help us find out (depending on the type of query):
$$$^\dagger \text{}$$$ Persik is a shark in the world of programming.
$$$^\ddagger$$$ A bracket sequence is called valid if it can be turned into a correct mathematical expression by adding only the symbols $$$+$$$ and $$$1$$$. For example, the sequences $$$(())(), (), (()(()))$$$ and the empty string are valid, while $$$)(, (()$$$ and $$$(()))($$$ are not.
The first line contains a single number $$$T$$$ — the number of test cases $$$(1 \le T \le 10\,000)$$$.
The second line contains a single number $$$Q$$$ — the type of query (common for all test cases) $$$(1 \le Q \le 2)$$$.
In the following $$$T$$$ lines, one bracket sequence is given per line. $$$(2 \le |s_i| \le 2^{22})$$$.
The total length of all input sequences does not exceed $$$2^{22}$$$ $$$(\sum_{i = 1}^T |s_i| \le 2^{22})$$$.
For each string, output the required number:
For $$$Q = 1$$$ — the number of different permutations such that the resulting string is a VBS.
For $$$Q = 2$$$ — the number of different VBS that can be obtained through such actions.
| Group | Points | Additional Constraints | Required Groups |
| 1 | 18 | $$$q = 1$$$, $$$\sum_{i = 1}^T |s_i| \le 2^8$$$ | – |
| 2 | 26 | $$$q = 1$$$, $$$\sum_{i = 1}^T |s_i| \le 2^{14}$$$ | 1 |
| 3 | 26 | $$$q = 1$$$, $$$\sum_{i = 1}^T |s_i| \le 2^{22}$$$ | 1, 2 |
| 4 | 13 | $$$q = 2$$$, $$$\sum_{i = 1}^T |s_i| \le 2^{12}$$$ | – |
| 5 | 17 | $$$q = 2$$$, $$$\sum_{i = 1}^T |s_i| \le 2^{17}$$$ | 4 |
21))((((()))()
2 2
22))((((()))()
1 2
If you take the string $$$s = (^1(^2)^3)^4$$$ (with the original position indicated after each symbol), it is itself a VBS, and also after one step with $$$x = 1, m = 2$$$ we get the string $$$(^2(^1)^4)^3$$$. In total, there are two options.
The illustration shows the application of one step $$$x = 2, m = 4$$$ to the string $$$((()))()$$$.
Illustration for the example