33OJ
登录 注册

#P18093. [CCPC 2026 长春站] 无忧旋律

[CCPC 2026 长春站] 无忧旋律

Problem 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 aa of length kk such that aa is a cyclic shift of the sequence [1,2,…,k][1,2,\ldots,k], that is, there exists a non-negative integer pp (0≤p<k)(0\le p <k) such that a=[p+1,p+2,…,k,1,2,…,p]a=[p+1,p+2,\dots,k,1,2,\dots,p]. Then she repeated this phrase again and again, and took the first nn notes to obtain the original score bb.

For example, when k=4k = 4, aa can be one of [1,2,3,4][1, 2, 3, 4], [2,3,4,1][2, 3, 4, 1], [3,4,1,2][3, 4, 1, 2] or [4,1,2,3][4, 1, 2, 3]. If a=[2,3,4,1]a = [2, 3, 4, 1] and n=10n = 10, then b=[2,3,4,1,2,3,4,1,2,3]b = [2, 3, 4, 1, 2, 3, 4, 1, 2, 3].

Before giving the melody to little ω\omega, little ε\varepsilon wants to add a color of her own to it: she may perform any number of modifications, and in each modification she may change the note at some position of the score into any positive integer. After several modifications, the original score bb becomes the score b′b' that little ω\omega finally hears.

Little ω\omega heard this melody b′b', and learned the number kk from little ε\varepsilon's sleep talk. Now little ω\omega wants to know the minimum number of notes little ε\varepsilon had to modify to turn the original score bb into the b′b' that she finally heard.

Input Format

The first line contains an integer TT (1≤T≤1041\le T\le 10^4), the number of test cases.

Each test case consists of two lines:

  • The first line contains two integers n,kn,k (2≤k≤n≤2×1052\le k\le n\le 2\times 10^5), the length of the score and the length of the phrase.
  • The second line contains nn integers b1′,b2′,…,bn′b'_1,b'_2,\ldots,b'_n (1≤bi′≤1091\le b'_i\le 10^9), the pitches of the notes that little ω\omega finally hears.

It is guaranteed that the sum of nn over all test cases in a single test point does not exceed 2×1052\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.

8
6 3
2 3 1 2 3 1
5 3
1 2 3 1 3
5 4
4 3 2 1 4
6 3
1 3 1 3 1 3
5 2
1 1 1 1 1
6 4
1 2 3 4 5 6
6 2
172 723 593 904 219 576
5 3
3 1 1000000000 999999999 1
0
1
2
4
2
2
6
2

Hint

For the first test case, one can take a=[2,3,1]a=[2,3,1]. Then the original score is exactly b=[2,3,1,2,3,1]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]a=[1,2,3], obtaining b=[1,2,3,1,2]b=[1,2,3,1,2]. It suffices to change the last note into 33 to obtain the final score, so the answer is 11.

For the third test case, one can take a=[4,1,2,3]a=[4,1,2,3], obtaining b=[4,1,2,3,4]b=[4,1,2,3,4]. It suffices to change the 22-nd note into 33 and the 44-th note into 11 to obtain the final score, so the answer is 22.

Translated by QwenWork