P18093 [CCPC 2026 Changchun] Carefree Melody
Description
Little $\varepsilon$ and little $\omega$ are two girls who love music. To commemorate a memory that belongs only to the two of them, little $\varepsilon$ wrote a melody for little $\omega$.
Little $\varepsilon$ recorded every note in the movement as an integer according to its pitch. She chose a phrase $a$ of length $k$ such that $a$ is a cyclic shift of the sequence $[1,2,\ldots,k]$, that is, there exists a non-negative integer $p$ $(0\le p
Input Format
The first line contains an integer $T$ ($1\le T\le 10^4$), the number of test cases.
Each test case consists of two lines:
- The first line contains two integers $n,k$ ($2\le k\le n\le 2\times 10^5$), the length of the score and the length of the phrase.
- The second line contains $n$ integers $b'_1,b'_2,\ldots,b'_n$ ($1\le b'_i\le 10^9$), the pitches of the notes that little $\omega$ finally hears.
It is guaranteed that the sum of $n$ over all test cases in a single test point does not exceed $2\times 10^5$.
Output Format
For each test case, output a single line with one non-negative integer, the minimum number of notes that little $\varepsilon$ modified.
Explanation/Hint
For the first test case, one can take $a=[2,3,1]$. Then the original score is exactly $b=[2,3,1,2,3,1]$, which is the same as the final score, so little $\varepsilon$ did not modify any note.
For the second test case, one can take $a=[1,2,3]$, obtaining $b=[1,2,3,1,2]$. It suffices to change the last note into $3$ to obtain the final score, so the answer is $1$.
For the third test case, one can take $a=[4,1,2,3]$, obtaining $b=[4,1,2,3,4]$. It suffices to change the $2$-nd note into $3$ and the $4$-th note into $1$ to obtain the final score, so the answer is $2$.
Translated by QwenWork