Bogdan is giving Carlo orthography lessons! The course will be held in days, during which Carlo will have to copy the string written on the blackboard as an exercise. The string is initially empty, and each day () will be extended by Bodgan with copies of the character that is the lesson's topic. More formally, the exercise string will be as follows:
- consists of characters equal to ;
- is the concatenation of and characters equal to .
Carlo is very prone to mistakes and on day he will get up to letters wrong. Thus, the string he will write on that day will differ from in at most positions. Bogdan would like to know the minimum possible imbalance of the strings Carlo will write. We define the imbalance of a string of length as the number of pair of indices such that and .
Input data
The first line of the input file contains a single integer , the number of test cases. test cases follow, each preceded by an empty line. Each test case consists of:
- a line containing integer .
- lines, the -th of which consisting of integer ; character and integer .
Output data
For each query from each testcase, output a single line containing one integer denoting the answer for that query.
Constraints and clarifications
- .
- .
- .
- .
- is a lowercase or uppercase letter of the English alphabet.
- The sum of over all test cases does not exceed .
# | Points | Constraints |
---|---|---|
1 | 0 | Examples. |
2 | 20 | and for every . |
3 | 20 | a or b for every . |
4 | 30 | is a lowercase letter for every . |
5 | 30 | No additional limitations. |
Examples
stdin
2
3
2 a 0
3 b 3
2 c 2
2
2 A 10
3 a 1
stdout
0
0
10
0
4
Explanation
In the first testcase of the sample case:
- =
aa
. Its imbalance is and it is possible for Carlo to copy it correctly. - =
aabbb
. It is possible for Carlo to writeaaaaa
, which has an imbalance of . - =
aabbbcc
. Its imbalance is . It is possible for Carlo to writeaabbbbb
, which has an imbalance of . He cannot write a string with a lower imbalance with up to mistakes.