CF1791D.Distinct Split

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

Distinct Split

Let's denote the f(x)f(x) function for a string xx as the number of distinct characters that the string contains. For example f(abc)=3f(\texttt{abc}) = 3, f(bbbbb)=1f(\texttt{bbbbb}) = 1, and f(babacaba)=3f(\texttt{babacaba}) = 3.

Given a string ss, split it into two non-empty strings aa and bb such that f(a)+f(b)f(a) + f(b) is the maximum possible. In other words, find the maximum possible value of f(a)+f(b)f(a) + f(b) such that a+b=sa + b = s (the concatenation of string aa and string bb is equal to string ss).

Input

The input consists of multiple test cases. The first line contains an integer tt (1t1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer nn (2n21052 \leq n \leq 2\cdot10^5) — the length of the string ss.

The second line contains the string ss, consisting of lowercase English letters.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5.

Output

For each test case, output a single integer  — the maximum possible value of f(a)+f(b)f(a) + f(b) such that a+b=sa + b = s.

Note

For the first test case, there is only one valid way to split aa into two non-empty strings a and a, and f(a)+f(a)=1+1=2f(\texttt{a}) + f(\texttt{a}) = 1 + 1 = 2.

For the second test case, by splitting abcabcd into abc and abcd we can get the answer of f(abc)+f(abcd)=3+4=7f(\texttt{abc}) + f(\texttt{abcd}) = 3 + 4 = 7 which is maximum possible.

For the third test case, it doesn't matter how we split the string, the answer will always be 22.

Samples

5
2
aa
7
abcabcd
5
aaaaa
10
paiumoment
4
aazz
2
7
2
10
3

在线编程 IDE

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