H. Max Min LCS
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given a string $$$s$$$ of lowercase Latin letters. You need to rearrange the characters of $$$s$$$ to form a new string $$$t$$$ such that the following value is maximized:

$$$$$$\min(\mathrm{LCS}(s, t), \mathrm{LCS}(s, \overline{t})).$$$$$$

Note:

  • $$$\mathrm{LCS}(s, t)$$$ equals the length of the longest common subsequence of the strings $$$s$$$ and $$$t$$$.
  • $$$\overline{t}$$$ represents the reversed string of $$$t$$$. For example, if $$$t=abdc$$$, $$$\overline{t} = cdba$$$.
Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.

Each test case consists of a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^3$$$) — the length of the string $$$s$$$ followed by $$$s$$$ on a new line.

It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$5 \cdot 10^3$$$.

Output

For each test case, print a single integer — the maximum possible value of the above expression among all rearrangements $$$t$$$ of $$$s$$$.

Example
Input
5
4
abcd
5
abcba
3
aaa
12
adhocsmatter
7
abccabc
Output
2
5
3
7
5