CF2072B.Having Been a Treasurer in the Past, I Help Goblins Deceive

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Having Been a Treasurer in the Past, I Help Goblins Deceive

After completing the first quest, Akito left the starting cave. After a while, he stumbled upon a goblin village.

Since Akito had nowhere to live, he wanted to find out the price of housing. It is well known that goblins write numbers as a string of characters '-' and '_', and the value represented by the string ss is the number of distinct subsequences^{\text{∗}} of the string ss that are equal to the string "-\_-" (this is very similar to goblin faces).

For example, the string s=s="-\_--\_-" represents the number 66, as it has 66 subsequences "-\_-":

  1. s1+s2+s3s_1+s_2+s_3
  2. s1+s2+s4s_1+s_2+s_4
  3. s1+s2+s6s_1+s_2+s_6
  4. s1+s5+s6s_1+s_5+s_6
  5. s3+s5+s6s_3+s_5+s_6
  6. s4+s5+s6s_4+s_5+s_6

Initially, the goblins wrote a random string-number ss in response to Akito's question, but then they realized that they wanted to take as much gold as possible from the traveler. To do this, they ask you to rearrange the characters in the string ss so that the value of the number represented by the string ss is maximized.

^{\text{∗}}A subsequence of a string aa is a string bb that can be obtained by deleting several (possibly 00) characters from aa. Subsequences are considered different if they are obtained by deleting different sets of indices.

Input

The first line contains the number tt (1t1041 \le t \le 10^4) — the number of test cases.

In the first line of each test case, there is one number nn (1n21051 \le n \le 2 \cdot 10^5) — the length of the string written by the goblins.

In the second line of each test case, there is a string ss of length nn, consisting only of characters '-' and '_' — the string written by the goblins.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, you need to output one number — the maximum number of subsequences equal to the string "-_-", if the characters in the string ss are optimally rearranged.

Note

In the first test case, it is beneficial to rearrange the characters to form the string "-_-". This is the only string of three characters that has at least one subsequence "-_-".

In the second test case, there is only one character "-", and at least two are needed for the subsequence "-_-". This means that for any rearrangement of characters, the answer will be 00.

In the seventh and eighth test cases, the length of the string n<3n \lt 3, which means that subsequences of length 33 do not exist.

Samples

8
3
--_
5
__-__
9
--__-_---
4
_--_
10
_-_-_-_-_-
7
_------
1
-
2
_-
1
0
27
2
30
9
0
0

在线编程 IDE

建议全屏模式获得最佳体验