Codeforces Round 630 (Div. 2)
C
K-Complete Word
Codeforces
1500
原题
← BD →
翻译中…

Word $s$ of length $n$ is called $k$-complete if

翻译中…
  • $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$;
  • $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \le i \le n-k$.
翻译中…

For example, "abaaba" is a $3$-complete word, while "abccba" is not.

翻译中…

Bob is given a word $s$ of length $n$ consisting of only lowercase Latin letters and an integer $k$, such that $n$ is divisible by $k$. He wants to convert $s$ to any $k$-complete word.

翻译中…

To do this Bob can choose some $i$ ($1 \le i \le n$) and replace the letter at position $i$ with some other lowercase Latin letter.

翻译中…

So now Bob wants to know the minimum number of letters he has to replace to convert $s$ to any $k$-complete word.

翻译中…

Note that Bob can do zero changes if the word $s$ is already $k$-complete.

翻译中…

You are required to answer $t$ test cases independently.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($1 \le k \lt n \le 2 \cdot 10^5$, $n$ is divisible by $k$).

翻译中…

The second line of each test case contains a word $s$ of length $n$.

翻译中…

It is guaranteed that word $s$ only contains lowercase Latin letters. And it is guaranteed that the sum of $n$ over all test cases will not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output one integer, representing the minimum number of characters he has to replace to convert $s$ to any $k$-complete word.

翻译中…

Note

翻译中…

In the first test case, one optimal solution is aaaaaa.

翻译中…

In the second test case, the given word itself is $k$-complete.

翻译中…

样例

Input #1
4
6 2
abaaba
6 3
abaaba
36 9
hippopotomonstrosesquippedaliophobia
21 7
wudixiaoxingxingheclp
Output #1
2
0
23
16
InputCopy OutputCopy
题目信息
题号
1332C
时间限制
2 s
内存限制
512 MB
标签
DFS 及类似
并查集
贪心
模拟
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。