265 传统题

[CF2290D] 字母降格 (Letters Down)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
3

[CF2290D] 字母降格 (Letters Down)

Problem Statement

You are given a string ss of length nn consisting of lowercase English letters.

In one operation, you may choose any lowercase letter x≠’a’x \ne \texttt{'a'} and replace all occurrences of xx in ss with the immediately preceding letter in the alphabet (for example, changing every 'c' to 'b'). If xx does not appear in ss, the string remains unchanged.

Find the minimum number of operations required to turn ss into a palindrome.

Input

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

Each test case consists of nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) on the first line, and the lowercase string ss of length nn on the second line.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, print a single integer — the minimum number of operations to make ss a palindrome.

Example

5
4
abca
4
abdc
7
racecar
4
cbad
4
zaza
1
3
0
2
25

Note

  • Constraints: 1≤t≤1041 \le t \le 10^4, 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, ∑n≤2⋅105\sum n \le 2 \cdot 10^5.
  • Source: Codeforces 2290D · Letters Down