GLaDOS, the artificial intelligence of the Aperture Science Enrichment Center, decided to conduct another test for Chell. This time, the test is about cakes.
GLaDOS arranged $$$n$$$ cakes in a row. Each cake can be either real (T) or fake (F). Chell must guess which cakes are real and which are fake. Chell has a unique ability: she can determine exactly whether a cake is real just by looking at it. However, in her answer, she must satisfy GLaDOS's strange condition: all fake cakes in Chell's answer must form one contiguous subsegment (possibly empty).
Initially, GLaDOS prepared some arrangement of cakes, but some cakes have not been placed yet. You are given a string $$$s$$$ of length $$$n$$$ describing the current situation:
GLaDOS, being cunning, wants to make Chell's life harder. She wants to place the remaining cakes (replace all N with T or F) so that the number of mistakes Chell is forced to make, under her optimal choice of segment, is as large as possible.
Help GLaDOS determine the maximum number of mistakes she can guarantee.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 500$$$) — the number of cakes.
The second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of the characters T, F, or N — the current arrangement of cakes.
It is guaranteed that the sum of $$$n^3$$$ over all test cases does not exceed $$$500^3$$$.
For each test case, output one integer — the maximum number of mistakes that GLaDOS can guarantee.
104FTFF5TNFTT6TFTTTN6TNNFTF7TNFNTNF6NNFFNN7TNTFNTN1N5NNNNN10NNNTTNNNFN
1012222023
In the first test case, $$$s =$$$ FTFF, all cakes are already placed. Chell will choose the segment $$$[3, 4]$$$, resulting in the answer TTFF, and she will have $$$1$$$ error.
In the second test case, $$$s =$$$ TNFTT, $$$1$$$ cake is not placed. For any replacement of N with T or F, the fake cakes form a continuous segment that Chell can choose, so the answer is $$$0$$$.
In the third test case, $$$s =$$$ TFTTTN, GLaDOS will replace N with F, obtaining TFTTTF. It can be shown that the answer is at least $$$1$$$. If Chell chooses the segment $$$[2, 2]$$$, i.e., gives the answer TFTTTT, she will make exactly $$$1$$$ error.
In the fourth test case, $$$s =$$$ TNNFTF, GLaDOS will arrange the cakes as follows: TFTFTF. Chell will choose the segment $$$[2, 4]$$$ (answer: TFFFTT), making $$$2$$$ errors.