#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a[N];
const int maxc = 60;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;cin >> t;
while(t--)
{
int n, k;cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = n;//最大可能的范围
//由题目可以知道,颜色最多有60种
//用枚举法将所有颜色列出来,找出统一颜色操作的最小值
for(int i = 1; i <= maxc; i++)
{
//注意数组开头有可能是目标颜色
int cnt = 0, idx = 0;//分别为次数和下标
while(idx < n && a[idx+1] == i) idx++;
while(idx < n)
{
idx += k;
while(idx < n && a[idx+1] == i) idx++;
cnt++;
}
ans = min(ans,cnt);
}
cout << ans << '\n';
}
return 0;
}