#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#define  mod 4294967296
#define mod 1000000007
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;

    }
    return true;
}
bool checkpalindrome(ll c)
{
    string p=to_string(c);
       int j = p.size() - 1;

    for (int i = 0; i < j; i++, j--)
    {
        if (p[i] != p[j])
        {
            return false;
        }
    }

    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}
unsigned int countSetBits(unsigned int n) //no. of 1's in a binary representation of a number
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
int computeXOR(int n)
{
  if(n%4==0)
  return n;                        //TO CALCULATE XOR FROM 1 TO N
  if(n%4==1)
  return 1;
  if(n%4==2)
  return n+1;
  else
  return 0;
}
ll largest_power(ll N)
    {                                              //LARGEST POWER OF 2 JUST LESS THAN OR EQUAL TO A GIVEN 16 BIT NUMBER
        //changing all right side bits to 1.
        N = N| (N>>1);
        N = N| (N>>2);
        N = N| (N>>4);
        N = N| (N>>8);
        N = N| (N>>16);

    //as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
                return (N+1)>>1;

    }
ll fibo(ll n)
{
    long double him=(1+sqrt(5))/2;
  return round(pow(him,n)/sqrt(5));
}
/*               Yhi patak ke chod denge
                 Chal nikal madarch*d                            */

int main()
{
     IOS
     int testcases=1;
     cin>>testcases;
     while(testcases--)
     {
        int n,k;
        cin>>n>>k;
        vector<int> v[n+1];
        int a[n];
        int p,c=0,m=0;
        for(int i=0;i<n;i++)
        {
            cin>>p;
            a[i]=p;
            v[p].pb(i+1);
        }
       for(int i=1;i<=n;i++)
       {
           if(v[i].size()>m)
           {
               m=v[i].size();
               c=i;
           }
       }
      // cout<<c<<" ";
       p=0;
       for(int i=0;i<n;i+=k)
       {
           m=0;
           for(int j=i;j<i+k && j<n;j++)
           {
               if(a[j]!=c)
               m=1;
           }
           if(m)
           {
               p++;
           }
           while(a[i+k]==c && i+k<n)
           i++;
       }
       cout<<p<<endl;

     }
     return 0;
}
//ascii of a=97
//ascii of A=65
//ascii of 0=48
//lower_bound and upper_bound


#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#define  mod 4294967296
#define mod 1000000007
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;

    }
    return true;
}
bool checkpalindrome(ll c)
{
    string p=to_string(c);
       int j = p.size() - 1;

    for (int i = 0; i < j; i++, j--)
    {
        if (p[i] != p[j])
        {
            return false;
        }
    }

    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}
unsigned int countSetBits(unsigned int n) //no. of 1's in a binary representation of a number
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
int computeXOR(int n)
{
  if(n%4==0)
  return n;                        //TO CALCULATE XOR FROM 1 TO N
  if(n%4==1)
  return 1;
  if(n%4==2)
  return n+1;
  else
  return 0;
}
ll largest_power(ll N)
    {                                              //LARGEST POWER OF 2 JUST LESS THAN OR EQUAL TO A GIVEN 16 BIT NUMBER
        //changing all right side bits to 1.
        N = N| (N>>1);
        N = N| (N>>2);
        N = N| (N>>4);
        N = N| (N>>8);
        N = N| (N>>16);

    //as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
                return (N+1)>>1;

    }
ll fibo(ll n)
{
    long double him=(1+sqrt(5))/2;
  return round(pow(him,n)/sqrt(5));
}
/*               Yhi patak ke chod denge
                 Chal nikal madarch*d                            */

int main()
{
     IOS
     int testcases=1;
     cin>>testcases;
     while(testcases--)
     {
        int n,k;
        cin>>n>>k;
        vector<int> v(n+1);
        int a[n];
        int p,c=0,m=0;
        for(int i=0;i<n;i++)
        {
            cin>>p;
            a[i]=p;
            v[p]++;
        }
       for(int i=1;i<=n;i++)
       {
           if(v[i]>m)
           {
               m=v[i];
               c=i;
           }
       }
      // cout<<c<<" ";
       p=0;
       for(int i=0;i<n;i+=k)
       {
           m=0;
           while( i<n && a[i]==c)
           i++;
           for(int j=i;j<i+k && j<n;j++)
           {
               if(a[j]!=c)
               m=1;
           }
           if(m)
           {
               p++;
           }
       }
       cout<<p<<endl;

     }
     return 0;
}
//ascii of a=97
//ascii of A=65
//ascii of 0=48
//lower_bound and upper_bound


#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#define  mod 4294967296
#define mod 1000000007
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;

    }
    return true;
}
bool checkpalindrome(ll c)
{
    string p=to_string(c);
       int j = p.size() - 1;

    for (int i = 0; i < j; i++, j--)
    {
        if (p[i] != p[j])
        {
            return false;
        }
    }

    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}
unsigned int countSetBits(unsigned int n) //no. of 1's in a binary representation of a number
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
int computeXOR(int n)
{
  if(n%4==0)
  return n;                        //TO CALCULATE XOR FROM 1 TO N
  if(n%4==1)
  return 1;
  if(n%4==2)
  return n+1;
  else
  return 0;
}
ll largest_power(ll N)
    {                                              //LARGEST POWER OF 2 JUST LESS THAN OR EQUAL TO A GIVEN 16 BIT NUMBER
        //changing all right side bits to 1.
        N = N| (N>>1);
        N = N| (N>>2);
        N = N| (N>>4);
        N = N| (N>>8);
        N = N| (N>>16);

    //as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
                return (N+1)>>1;

    }
ll fibo(ll n)
{
    long double him=(1+sqrt(5))/2;
  return round(pow(him,n)/sqrt(5));
}
/*               Yhi patak ke chod denge
                 Chal nikal madarch*d                            */

int main()
{
     IOS
     int testcases=1;
     cin>>testcases;
     while(testcases--)
     {
        int n,k;
        cin>>n>>k;
        vector<int> v[n+1];
        int a[n];
        int p,c=0,m=0;
        for(int i=0;i<n;i++)
        {
            cin>>p;
            a[i]=p;
            v[p].pb(i+1);
        }
       for(int i=1;i<=n;i++)
       {
           if(v[i].size()>m)
           {
               m=v[i].size();
               c=i;
           }
       }
      // cout<<c<<" ";
       p=0;
       for(int i=0;i<n;i+=k)
       {
           m=0;
           for(int j=i;j<i+k && j<n;j++)
           {
               if(a[j]!=c)
               m=1;
           }
           if(m)
           {
               p++;
           }
           while( i+k<n && a[i+k]==c)
           i++;
       }
       cout<<p<<endl;

     }
     return 0;
}
//ascii of a=97
//ascii of A=65
//ascii of 0=48
//lower_bound and upper_bound


#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#define  mod 4294967296
#define mod 1000000007
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;

    }
    return true;
}
bool checkpalindrome(ll c)
{
    string p=to_string(c);
       int j = p.size() - 1;

    for (int i = 0; i < j; i++, j--)
    {
        if (p[i] != p[j])
        {
            return false;
        }
    }

    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}
unsigned int countSetBits(unsigned int n) //no. of 1's in a binary representation of a number
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
int computeXOR(int n)
{
  if(n%4==0)
  return n;                        //TO CALCULATE XOR FROM 1 TO N
  if(n%4==1)
  return 1;
  if(n%4==2)
  return n+1;
  else
  return 0;
}
ll largest_power(ll N)
    {                                              //LARGEST POWER OF 2 JUST LESS THAN OR EQUAL TO A GIVEN 16 BIT NUMBER
        //changing all right side bits to 1.
        N = N| (N>>1);
        N = N| (N>>2);
        N = N| (N>>4);
        N = N| (N>>8);
        N = N| (N>>16);

    //as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
                return (N+1)>>1;

    }
ll fibo(ll n)
{
    long double him=(1+sqrt(5))/2;
  return round(pow(him,n)/sqrt(5));
}
/*               Yhi patak ke chod denge
                 Chal nikal madarch*d                            */

int main()
{
     IOS
     int testcases=1;
     cin>>testcases;
     while(testcases--)
     {
        int n,k;
        cin>>n>>k;
        vector<int> v[n+1];
        int a[n];
        int p,c=0,m=0;
        for(int i=0;i<n;i++)
        {
            cin>>p;
            a[i]=p;
            v[p].pb(i+1);
        }
       for(int i=1;i<=n;i++)
       {
           if(v[i].size()>m)
           {
               m=v[i].size();
               c=i;
           }
       }
      // cout<<c<<" ";
       p=0;
       for(int i=0;i<n;i+=k)
       {
           m=0;
           while( i<n && a[i]==c)
           i++;
           for(int j=i;j<i+k && j<n;j++)
           {
               if(a[j]!=c)
               m=1;
           }
           if(m)
           {
               p++;
           }
       }
       cout<<p<<endl;

     }
     return 0;
}
//ascii of a=97
//ascii of A=65
//ascii of 0=48
//lower_bound and upper_bound


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define int long long
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("ai.txt", "r", stdin);
	freopen("ao.txt", "w", stdout);
#endif
	fio;

	tc(t){

		int ans=INT_MAX;
		int n,k;
		cin>>n>>k;
		int a[n];
		set<int>s;

		for(int i=0;i<n;i++){
			cin>>a[i];
			s.insert(a[i]);
		}
		auto it=s.begin();
		while(it!=s.end()){

			int finl=0;
			int x=*it;
			int i=0;

			while(i<n){
				if(x==a[i]){
					i++;
				}else{
					finl++;
					i+=k;
				}
			}
			ans=min(ans,finl);
			it++;
		}
		cout<<ans<<endl;

	}
}


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define int long long
#define ll long long
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("ci.txt", "r", stdin);
	freopen("co.txt", "w", stdout);
#endif
	fio;

	tc(t) {

		int n,k;
		cin>>n>>k;

		arrip(a,n);

        map<int,int>m;

        for(int i=0;i<n;i++){
            m[a[i]]++;
        }
        int result,maxi=INT_MIN;
        for(auto itr:m){
            if(itr.second>maxi){
                result=itr.first;
                maxi=itr.second;
            }
        }
       int num=n-maxi;
       if(num%k!=0){
           cout<<(num/k)+1<<endl;
       }else{
           cout<<(num/k)<<endl;
       }
	}
}


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define int long long
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("ai.txt", "r", stdin);
	freopen("ao.txt", "w", stdout);
#endif
	fio;

	tc(t){

		int ans=INT_MAX;
		int n,k;
		cin>>n>>k;
		int a[n];
		set<int>s;

		for(int i=0;i<n;i++){
			cin>>a[i];
			s.insert(a[i]);
		}
		auto it=s.begin();
		while(it!=s.end()){

			int finl=0;
			int x=*it;
			int i=0;

			while(i<n){
				if(x==a[i]){
					i++;
				}else{
					finl++;
					i+=k;
				}
			}
			ans=min(ans,finl);
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define int long long
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("bi.txt", "r", stdin);
	freopen("bo.txt", "w", stdout);
#endif
	fio;

	tc(t){

		int n,k;
		cin>>n>>k;

		arrip(a,n);
		int ans=INT_MAX;
		set<int>s;

		for(int i=0;i<n;i++){
			s.insert(a[i]);
		}

		int i=0;
		int cnt=0;
		auto itr=s.begin();
		while(itr!=s.end()){

			int x=*(itr);
			int cnt=0;
			int i=0;
			while(i<n){

				if(x==a[i]){
					i++;
				}else{
					cnt++;
					i+=k;
				}
			}
			ans=min(ans,cnt);
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define int long long
#define ll long long
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("ci.txt", "r", stdin);
	freopen("co.txt", "w", stdout);
#endif
	fio;

	tc(t) {

		int n,k;
		cin>>n>>k;

		arrip(a,n);
        int fin=0;
        for(int i=0;i<n;i++){
            if(a[i]!=a[i+1]){
                fin++;
            }
        }

        if(fin==n){
            cout<<n-1<<endl;
        }else{
        map<int,int>m;

        for(int i=0;i<n;i++){
            m[a[i]]++;
        }
        int result,maxi=INT_MIN;
        for(auto itr:m){
            if(itr.second>maxi){
                result=itr.first;
                maxi=itr.second;
            }
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]!=result){
                cnt++;
            }
        }
        cout<<(cnt/k)+1<<endl;
	}
	}
}


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define int long long
#define ll long long
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("ci.txt", "r", stdin);
	freopen("co.txt", "w", stdout);
#endif
	fio;

	tc(t) {

		int n,k;
		cin>>n>>k;

		arrip(a,n);
        int fin=0;
        for(int i=0;i<n;i++){
            if(a[i]!=a[i+1]){
                fin++;
            }
        }

        if(fin==n){
            cout<<n-1<<endl;
        }else{
        map<int,int>m;

        for(int i=0;i<n;i++){
            m[a[i]]++;
        }
        int result,maxi=INT_MIN;
        for(auto itr:m){
            if(itr.second>maxi){
                result=itr.first;
            }
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]!=result){
                cnt++;
                while(a[i]!=result)
                i++;
            }
        }
        cout<<cnt<<endl;
        }
	}

}


#include <bits/stdc++.h>
using namespace std;

// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define int long long
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(a,n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("ai.txt", "r", stdin);
	freopen("ao.txt", "w", stdout);
#endif
	fio;

	tc(t){

		int ans=INT_MAX;
		int n,k;
		cin>>n>>k;
		int a[n];
		set<int>s;

		for(int i=0;i<n;i++){
			cin>>a[i];
			s.insert(a[i]);
		}
		auto it=s.begin();
		while(it!=s.end()){

			int finl=0;
			int x=*it;
			int i=0;

			while(i<n){
				if(x==a[i]){
					i++;
				}else{
					finl++;
					i+=k;
				}
			}
			ans=min(ans,finl);
		}
		cout<<ans<<endl;
		it++;
	}
}


#include"bits/stdc++.h"
using namespace std;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n,k,ans=n+1,tt;
		cin >> n >> k;
		int a[n];
		for(int i=0;i<n;i++)cin >> a[i];
		for(int i=1;i<=100;i++)
		{
			tt=0;
			for(int j=0;j<n;j++)
			{
				if(a[j]==i)
				continue;
				else
				{
					j=j+k-1;
					tt++;
				}
			}
			if(ans>tt)
			ans=tt;
		}
		cout << ans << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

int solve(vector<int> arr, int window)
{
	map<int, int> color_freq;

	for (int j = 0; j < arr.size(); j++) {
		color_freq[arr[j]]++;
	}
	int max_color = 0;
	int max_count = 0;
	auto it = color_freq.begin();
	for (; it != color_freq.end(); it++) {
		if (it->second > max_count)
			max_color = it->first;
	}
	sort(arr.begin(), arr.end());
	auto start_max = lower_bound(arr.begin(), arr.end(), max_color);
	auto end_max = upper_bound(arr.begin(), arr.end(), max_color);
	auto start = arr.begin();
	auto end = arr.end();

	int diff1 = start_max - start;
	int diff2 = end - end_max;

	int sum = ceil((double)diff1 / (double)window);
	sum += ceil((double)diff2 / (double)window);

	return sum;
}

int main() {
	// your code goes here
	int T = 0;
	cin >> T;
	for (int i = 0; i < T; i++) {
		int size;
		int window;
		cin >> size >> window;
		vector<int> arr;
		for (int j = 0; j < size; j++) {
			int val;
			cin >> val;
			arr.push_back(val);
		}
		int sum = solve(arr, window);
		cout << sum << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

int solve(vector<int> arr, int window)
{
	map<int, int> color_freq;

	for (int j = 0; j < arr.size(); j++) {
		color_freq[arr[j]]++;
	}
	int max_color = 0;
	int max_count = 0;
	auto it = color_freq.begin();
	for (; it != color_freq.end(); it++) {
		if (it->second > max_count)
			max_color = it->first;
	}
	sort(arr.begin(), arr.end());
	auto start_max = lower_bound(arr.begin(), arr.end(), max_color);
	auto end_max = upper_bound(arr.begin(), arr.end(), max_color);
	auto start = arr.begin();
	auto end = arr.end();

	int diff1 = start_max - start;
	int diff2 = end - end_max;

	if (window == 0)
		window = 1;
	int sum = ceil((double)diff1 / (double)window);
	sum += ceil((double)diff2 / (double)window);

	return sum;
}

int main() {
	// your code goes here
	int T = 0;
	cin >> T;
	for (int i = 0; i < T; i++) {
		int size;
		int window;
		cin >> size >> window;
		vector<int> arr;
		for (int j = 0; j < size; j++) {
			int val;
			cin >> val;
			arr.push_back(val);
		}
		int sum = solve(arr, window);
		cout << sum << endl;
	}
	return 0;
}


/************
Beautiful Codes are MUCH better than 'Shorter' ones !
Author :- Profesor(Abhishek)
29.11.2020  12.46.48
**********/
#include "bits/stdc++.h"
using namespace std;
#define ll long long
ll i, j, k;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define test() long long test;cin>>test;while(test--)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define for0(i, n) for (i = 0; i < n; i++)
#define for1(i, n) for (i = 1; i < n; i++)
#define loop(i,a,b) for(i=a;i<b;i++)
#define loopr(i,a,b) for(i=a;i>b;i--)
#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define pf emplace_front
#define mp make_pair
#define fi first
#define se second
#define que_max priority_queue <int>
#define que_min priority_queue <int, vi, greater<int> >
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define sll set<ll>
#define vll vector<ll>
#define msl map<string,ll>
#define mll map<ll,ll>
int main()
{
     test()
    {
         ll n, k;
         cin >> n >> k;
         ll arr[ n ], cnt = 0;
         mll mp;
         for0(i, n)
        {
             cin >> arr[ i ];
             mp[ arr[ i ] ]++;
             if (arr[ i ] == arr[ 0 ])
                 cnt++;
        }
         if(cnt == n)
        {
             cout << n;
             continue;
        }
         ll num=INT_MIN, x; // x is the most repeated number & num is the number of count of x
         forit(it, mp)
         {
             if(it->se >= num)
            {
                 x = it->fi;
                 num = it->se;
            }
         }
         ll ans = n - num;
         if (ans % k == 0)
             cout << ans / k << endl;
         else
         {
             cout << (ans / k) + 1<<endl;
         }

    }

   // cout << endl << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n,k,ans,tt;
		cin >> n >> k;
		ans=n+1;
		int a[n];
		for(int i=0;i<n;i++)cin >> a[i];
		for(int i=1;i<=100;i++)
		{
			tt=0;
			for(int j=0;j<n;j++)
			{
				if(a[j]==i)
				continue;
				else
				{
					j=j+k-1;
					tt++;
				}
			}
			if(ans>tt)
			ans=tt;
		}
		cout << ans << endl;
	}
}


#include"bits/stdc++.h"
using namespace std;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n,k,ans,tt;
		cin >> n >> k;
		ans=n+1
		int a[n];
		for(int i=0;i<n;i++)cin >> a[i];
		for(int i=1;i<=100;i++)
		{
			tt=0;
			for(int j=0;j<n;j++)
			{
				if(a[j]==i)
				continue;
				else
				{
					j=j+k-1;
					tt++;
				}
			}
			if(ans>tt)
			ans=tt;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll tc;
	cin>>tc;
	while(tc--)
	{
		ll n,k,a;
		cin>>n>>k;
		vector <ll> v1(100000,0);
		ll mx=-1;
		for(ll i=0;i<n;i++)
		{
			cin>>a;
			v1[a]++;
			mx=max(v1[a],mx);
		}
		cout<<((n-1-mx)/k)+1<<endl;

	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll tc;
	cin>>tc;
	while(tc--)
	{
		ll n,k,a,b,mx=-1;
		cin>>n>>k;
		ll arr[1000000]={0};
		vector <ll> v1;
		for(ll i=0;i<n;i++)
		{
			cin>>a;
			mx=max(arr[a],mx);
			v1.push_back(a);
			arr[a]++;
			if(arr[a]>=mx)
			{
				mx=arr[a];
				b=a;
			}
		}
		ll ans=0,c=0;
		for(ll i=0;i<n;i++)
		{
			if(v1[i]==b)
			continue;
			else if(v1[i]!=b&&c<k)
			{
				v1[i]=b;
				if(c==0) ans++;
				c++;
				continue;
			}
			else if(v1[i]!=b)
			{
				c=0;
				i--;
				continue;
			}

		}
		cout<<ans<<endl;
	}
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n,k;
    cin>>n>>k;
    vector <int> arr(n),v;
    map <int,int> mp;
    int i,x,maxm=0,minans=INT_MAX;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it->second>maxm)
        {
            maxm=it->second;
            v.push_back(it->first);
        }
    }
    for(int c=0;c<v.size();c++)
    {
    x=v[c];
    vector <int> vec;
    for(int i=0;i<n;i++)
    {
        if(arr[i]!=x)
        {
            vec.push_back(i);
        }
    }
    int ans=0;
    for(i=0;i<vec.size();i++)
    {
        int y=vec[i]+k-1;
        while(vec[i]<=y)
        {
            i++;
        }
        ans++;
        i--;
    }
    if(ans<minans)
    minans=ans;
    }

    cout<<minans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
    	test();
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n,k;
    cin>>n>>k;
    vector <int> arr(n),vec,hash(101,0);
    int i,j,x,minans=INT_MAX;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        hash[arr[i]]++;
    }
    for(int x=1;x<=100;x++)
    {
        if(hash[x]==0)
        continue;
        vec.clear();
        int ans=0;
        for(j=0;j<n;j++)
        {
            if(arr[j]!=x)
            {
                vec.push_back(j);
            }
        }
        for(i=0;i<vec.size();i++)
        {
            int y=vec[i]+k-1;
            while(vec[i]<=y && i<n)
            {
                i++;
            }
            ans++;
            i--;
        }
        if(ans<minans)
        minans=ans;
    }
    cout<<minans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
    	test();
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n,k;
    cin>>n>>k;
    vector <int> arr(n);
    map <int,int> mp;
    int i,x,maxm=0;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it->second>maxm)
        {
            maxm=it->second;
            x=it->first;
        }
    }
    vector <int> vec;
    for(int i=0;i<n;i++)
    {
        if(arr[i]!=x)
        {
            vec.push_back(i);
        }
    }
    int ans=0;
    for(i=0;i<vec.size();i++)
    {
        int y=vec[i]+k-1;
        while(vec[i]<=y)
        {
            i++;
        }
        ans++;
        i--;
    }

    cout<<ans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
    	test();
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n,k;
    cin>>n>>k;
    vector <int> arr(n),vec;
    int i,j,x,minans=INT_MAX;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int x=1;x<=100;x++)
    {
        vec.clear();
        int ans=0;
        for(j=0;j<n;j++)
        {
            if(arr[j]!=x)
            {
                vec.push_back(j);
            }
        }
        for(i=0;i<vec.size();i++)
        {
            int y=vec[i]+k-1;
            while(vec[i]<=y)
            {
                i++;
            }
            ans++;
            i--;
        }
        if(ans<minans)
        minans=ans;
    }
    cout<<minans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
    	test();
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n,k;
    cin>>n>>k;
    vector <int> arr(n),v;
    map <int,int> mp;
    int i,x,maxm=0,minans=INT_MAX;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it->second>maxm)
        {
            maxm=it->second;
        }
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it->second==maxm)
        {
            v.push_back(it->first);
        }
    }
    for(int c=0;c<v.size();c++)
    {
    x=v[c];
    vector <int> vec;
    for(int i=0;i<n;i++)
    {
        if(arr[i]!=x)
        {
            vec.push_back(i);
        }
    }
    int ans=0;
    for(i=0;i<vec.size();i++)
    {
        int y=vec[i]+k-1;
        while(vec[i]<=y)
        {
            i++;
        }
        ans++;
        i--;
    }
    if(ans<minans)
    minans=ans;
    //cout<<x<<" "<<ans<<"\n";
    }

    cout<<minans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
    	test();
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
    int n,k;
    cin>>n>>k;
    vector <int> arr(n),vec,hash(101,0);
    int i,j,x,minans=INT_MAX;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        hash[arr[i]]++;
    }
    for(int x=1;x<=100;x++)
    {
        if(hash[x]==0)
        continue;
        vec.clear();
        int ans=0;
        for(j=0;j<n;j++)
        {
            if(arr[j]!=x)
            {
                vec.push_back(j);
            }
        }
        for(i=0;i<vec.size();i++)
        {
            int y=vec[i]+k-1;
            while(vec[i]<=y)
            {
                i++;
            }
            ans++;
            i--;
        }
        if(ans<minans)
        minans=ans;
    }
    cout<<minans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
    	test();
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=ceil(c*1.00/k);
            ll tm=c%k;
            j+=tm;
            j++;
            if(f)
                j--;

        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=ceil(c*1.00/k);
            ll tm=c%k;
            j+=tm;
            j++;

        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]==i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=(c/k);
        }
        ll tm=(n*1.00/k)-sum;
        mn=min(mn,tm);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=ceil(c*1.00/k);
            ll tm=c%k;
            j+=tm;

        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            if(f)
                j--;
            sum+=ceil(c*1.00/k);
        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=(c/k);
            ll tm=c%k;
            j+=tm;
            sum+=tm;
        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=(c/k);
            ll tm=c%k;
            j-=tm;
            if(tm)
            sum--;
        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while((a[j]!=i)||(c%k!=0)){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=c/k;

        }
        if(c%k)
            sum++;
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            if(f==1)
                j--;
            sum+=ceil(c*1.00/k);
            ll tm=c%k;
            j+=tm;

        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=(c/k);
            ll tm=c%k;
            j+=tm;
            if(tm)
            sum++;
        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=ceil(c*1.00/k);
            ll tm=c%k;
            j+=tm;
            if(f)
                j--;

        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;j++){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=ceil(c*1.00/k);
        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;

#define PI acos(-1.00)

void solve()
{
    ll n,k,sum=0,mn=1e18;
    cin>>n>>k;
    ll a[n],b[101];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=100;i++){
        ll c=0;
        sum=0;
        for(int j=0;j<n;){
            c=0;
            bool f=0;
            while(a[j]!=i){
                c++;
                j++;
                if(j==n)
                    break;
                f=1;
            }
            sum+=ceil(c*1.00/k);
            ll tm=c%k;
            j+=tm;
            if(!f)
                j++;

        }
        mn=min(mn,sum);

    }
    cout<<mn<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

         int n,k;
        cin>>n>>k;

        int A[n],x=0;
        map<int,int>P;
        for(int i=0;i<n;++i){
            cin>>A[i];
            P[A[i]]++;
            if(P[A[i]]==1)x++;
        }

       int ans=n+1;
		int temp;
		for(int i=1;i<=100;i++){
			temp=0;
			for(int j=0;j<n;j++)
			{
				if(A[j]==i)
				{
				    continue;
				}
				else
				{
					j=j+k-1;
					temp=temp+1;
				}
			}
			if(ans>temp) ans=temp;
		}
		cout << ans << endl;

    }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

         int n,k;
        cin>>n>>k;

        int A[n];
        map< int,int>P;
        int x=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            P[A[i]]++;
            if(P[A[i]]==1)x++;
        }
        if(x==n)
        {
            cout<<(n-1)<<endl;
            continue;
        }

         int tot=INT_MIN, z=0;
         for(auto it=(P).begin();it!=(P).end(); it++)
         {
             if(it->second >= tot)
            {
                 z = it->first;
                 tot = it->second;
            }
         }
         int c = n - tot;
         if (c % k == 0)
         {
             cout <<(c/k)<< endl;
         }
         else
         {
             cout <<((c/k)+1)<<endl;
         }

    }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

         int n,k;
        cin>>n>>k;

        int A[n];
        map< int,int>P;
        int x=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            P[A[i]]++;
            if(P[A[i]]==1)x++;
        }

         int tot=INT_MIN, z=0;
         for(auto it=(P).begin();it!=(P).end(); it++)
         {
             if(it->second >= tot)
            {
                 z = it->first;
                 tot = it->second;
            }
         }
         int c = n - tot;
         if (c % k == 0)
         {
             cout <<(c/k)<< endl;
         }
         else
         {
             cout <<((c/k)+1)<<endl;
         }

    }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;

        long int A[n];
        map<long int,int>P;
        long int mx=-1,x=0;int z=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            P[A[i]]++;
            if(mx<P[A[i]])
            {
                mx=P[A[i]];
                x=A[i];
            }
            if(P[A[i]]==1)z++;
        }

        long int temp=0;
        long int tot=0;
        int f=0;
        for(int i=0;i<n;++i)
        {
            if(f)
            {
                if(A[i]==x)
                {
                    f=0;
                    tot+=((i-temp)/k);
                    if((i-temp)%k)
                    {
                        tot++;
                    }
                }
                else
                {
                    if((i==n-1))
                    {
                        tot+=(((i+1)-temp)/k);
                    if((i-temp)%k)
                    {
                        tot++;
                    }
                    }
                }
            }
            else
            {
                if(A[i]!=x)
                {
                    f=1;
                    temp=i;
                    if(i==n-1)
                    {
                        tot++;
                    }

                }
            }
        }

        if(z==2)
        {
        long int tot2=0;
        temp=0;f=0;

        for(int i=0;i<n;++i)
        {
            if(f)
            {
                if(A[i]!=x)
                {
                    f=0;
                    tot2+=((i-temp)/k);
                    if((i-temp)%k)
                    {
                        tot2++;
                    }
                }
                else
                {
                    if((i==n-1))
                    {
                        tot2+=(((i+1)-temp)/k);
                    if((i-temp)%k)
                    {
                        tot2++;
                    }
                    }
                }
            }
            else
            {
                if(A[i]==x)
                {
                    f=1;
                    temp=i;
                    if(i==n-1)
                    {
                        tot++;
                    }

                }
            }
        }

        cout<<min(tot,tot2)<<endl;
        }
        else
        {
            cout<<tot<<endl;
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

         int n,k;
        cin>>n>>k;

        int A[n],x=0;
        map<int,int>P;
        for(int i=0;i<n;++i){
            cin>>A[i];
            P[A[i]]++;
            if(P[A[i]]==1)x++;
        }

       if(x==n)
       {
           if((n-1)%k)cout<<((n-1)/k+1)<<endl;
           else cout<<((n-1/k))<<endl;
       }
       else
       {
           int ans=INT_MAX;
           for(int i=1;i<=x;++i)
           {
                int temp=0;
             int tot=0;
            int f=0;
        for(int j=0;j<n;++j)
        {
            if(f)
            {
                if(A[j]==i)
                {
                    f=0;
                    tot+=((j-temp)/k);
                    if((j-temp)%k)
                    {
                        tot++;
                    }
                }
                else
                {
                    if((j==n-1))
                    {
                        tot+=(((j+1)-temp)/k);
                    if((j-temp)%k)
                    {
                        tot++;
                    }
                    }
                }
            }
            else
            {
                if(A[j]!=i)
                {
                    f=1;
                    temp=j;
                    if(j==n-1)
                    {
                        tot++;
                    }

                }
            }
        }

           ans=min(ans,tot);
           }

           cout<<ans<<endl;
       }

    }
     return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=99999999;
int a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		map<int,int>mp;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		mp[a[1]]=1;
		int maxx=0;
		for(int i=2;i<=n;i++)
		{
			if(a[i-1]!=a[i])
			{
				maxx=max(maxx,mp[a[i-1]]);
				mp[a[i-1]]=0;
				mp[a[i]]++;
			}
			else
			{
				mp[a[i]]++;
			}
		}
		cout<<(n-maxx)/k<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=99999999;
int a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		map<int,int>mp;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		if(n==1)
		{
			cout<<"0"<<endl;continue;
		}
		mp[a[1]]=1;
		int maxx=0;
		for(int i=2;i<=n;i++)
		{
			if(a[i-1]!=a[i])
			{
				maxx=max(maxx,mp[a[i-1]]);
				mp[a[i-1]]=0;
				mp[a[i]]++;
			}
			else
			{
				mp[a[i]]++;
			}
		}
		cout<<(n-maxx)/k<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=99999999;
int a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		map<int,int>mp;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		if(n==1)
		{
			cout<<"0"<<endl;continue;
		}
		int minn=inf;
		for(int i=1;i<=100;i++)
		{
			int ok=0;
			for(int j=1;j<=n;j++)
			{
				if(a[j]==i)
				{
					ok=1;break;
				}
			}
			if(!ok)
				continue;
			int cnt=0,sum=0;
			for(int j=1;j<=n;j++)
			{
				if(a[j]!=i)
				{
					cnt++;
				}
				else
				{
					int md=cnt/k;
					if(cnt%k!=0)
						md++;
					cnt=0;
					sum+=md;
				}
			}
			if(a[n]!=i)
			{
				int md=cnt/k;
				if(cnt%k!=0)
					md++;
				sum+=md;
			}
			minn=min(sum,minn);

		}
		cout<<minn<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=99999999;
int a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		map<int,int>mp;
		for(int i=1;i<=n;i++)
			cin>>a[i],mp[a[i]]++;
		if(n==1)
		{
			cout<<"0"<<endl;continue;
		}
		int minn=inf;
		for(int i=1;i<=100;i++)
		{
			if(mp[i]==0)
				continue;
			int cnt=0,sum=0;
			for(int j=1;j<=n;j++)
			{
				if(a[j]!=i)
				{
					cnt++;
				}
				else
				{
					int md=cnt/k;
					if(cnt%k!=0)
						md++;
					cnt=0;
					sum+=md;
				}
			}
			if(a[n]!=i)
			{
				int md=cnt/k;
				if(cnt%k!=0)
					md++;
				sum+=md;
			}
			minn=min(sum,minn);
		}
		cout<<minn<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=99999999;
int a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		map<int,int>mp;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		if(n==1)
		{
			cout<<"0"<<endl;continue;
		}
		mp[a[1]]=1;
		int maxx=0;
		int r=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i-1]!=a[i])
			{
				if(maxx<=mp[a[i-1]])
				{
					maxx=mp[a[i-1]];
					r=i-1;
				}
				mp[a[i-1]]=0;
				mp[a[i]]++;
			}
			else
			{
				mp[a[i]]++;
			}
		}
		if(maxx<=mp[a[n]])
		{
			r=n;
		}
		int l;
		for(int i=r-1;i>=1;i--)
		{
			if(a[i]!=a[i+1])
			{
				l=i+1;
				break;
			}
		}
		int c1=0;
		int sum=0;
		for(int i=1;i<l;i++)
		{
			if(a[i]!=a[l])
			{
				c1++;
			}
			else
			{
				sum+=(c1/k);
				if(c1%k!=0)
					sum++;
				c1=0;
			}
		}
		if(a[l-1]!=a[l])
		{
				sum+=(c1/k);
				if(c1%k!=0)
					sum++;
		}
		c1=0;
		for(int i=r+1;i<=n;i++)
		{
			if(a[i]!=a[l])
			{
				c1++;
			}
			else
			{
				sum+=(c1/k);
				if(c1%k!=0)
					sum++;
				c1=0;
			}
		}
		if(a[n]!=a[l])
		{
			sum+=(c1/k);
				if(c1%k!=0)
					sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=99999999;
int a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		map<int,int>mp;
		cin>>n>>k;
		for(int i=1;i<=n;i++)
			cin>>a[i],mp[a[i]]++;
		int minn=inf;
		for(int i=1;i<=100;i++)
		{
			if(mp[i]==0)
				continue;
			int cnt=0;
			int j;
			for(j=1;j<=n;)
			{
				if(a[j]!=i)
				{
					cnt++;
					j+=k;
				}
				else
				{
					j++;
				}
			}
			minn=min(minn,cnt);
		}
		cout<<minn<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
namespace __gnu_pbds {
    typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;
#define s(i) (ll)*(s.find_by_order((ll)i))

typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define dbg(var) cout<<#var<<"="<<var<<"\n"
#define f first
//#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=1000000007;
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ordered_set s;
bool _exist(ll x){
     return (((ll)*s.upper_bound(x))==x);
}
void _erase(ll x){
     if(_exist(x)){
        s.erase(s.upper_bound(x));
     }
}
int idx(ll x){

    if(!_exist(x)){
        return -1;
    }
    return (s.order_of_key((ll)x));
}
ll lastidx(ll x){

    if(!_exist(x)){
        return -1;
    }
    if(s(s.size()-1)==x){
        return s.size()-1;
    }
    else{
        return idx(*s.lower_bound(x))-1;
    }
}
ll _count(ll x){
     if(!_exist(x)){
        return 0;
     }
     return lastidx(x)-idx(x)+1;
}
int dp[100001],a[100001];
int n,k,x,y;
int solve(int idx){
  if(idx>=n)return 0;
  int &res=dp[idx];
  if(res!=-1)return res;
  res=int(1e9);
  if(a[idx]!=1){
    res=min(res,solve(idx+k)+x);
  }
  else{
    res=min(res,solve(idx+k));
  }
  return res;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    int p;
    cin>>n>>p>>k;
    st st1;
    cin>>st1>>x>>y;
    for(int i=0;i<n;++i){
        a[i]=st1[i]-'0';
        dp[i]=-1;
    }
    p--;
    int res=int(1e9);
    for(int i=p;i+k-1<n-1;++i){
      res=min(solve(i)+(y*(i-p)),res);
    }
    cout<<res<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001],csum[100001];
 int n,k;
ll f(ll idx){
for(int i=1;i<=n;++i){
        csum[i]=csum[i-1]+(a[i]!=idx);
    }
    ll mi=ll(1e18+4);
    for(int i=1;i<=k;++i){
        int j=i;
        ll res=0;
        if(csum[j-1]>0)res++;
        for(;j+k-1<=n;j+=k){
            if(csum[j+k-1]-csum[j-1]>0)res++;
        }
        if(csum[n]-csum[j-1]>0)res++;
        mi=min(mi,res);
    }
    return mi;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    cin>>n>>k;
    ll ma=0,idx=0;
    for(int i=1;i<=n;++i)csum[i]=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    for(int i=1;i<=n;++i){
        csum[i]=csum[i-1]+(a[i]!=idx);
    }
    ll mi=ll(1e18+4);
    for(int i=1;i<=100;++i){
        mi=min(mi,f(i));
    }
    cout<<mi<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001],csum[100001];
ll dp[100001];
int c;
int n,k;
ll solve(ll idx){
    if(idx>=n)return 0;
    ll &res=dp[idx];
    if(res!=-1)return res;
    res=ll(1e18);
    if(a[idx]==c){
        res=min(res,solve(idx+1));
    }
    else{
      for(int j=0;j<k;++j){
        if(idx-j>=0){
            res=min(res,solve(idx+k)+1);
        }
      }
    }
    return res;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    ll mi=ll(1e18);
    for(int i=1;i<=100;++i){
          for(int j=0;j<=n;++j)dp[j]=-1;
          c=i;
          mi=min(mi,solve(0));
    }
    cout<<mi<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001],csum[100001];
int n,k;
ll f(ll idx){
for(int i=1;i<=n;++i)csum[i]=0;
for(int i=1;i<=n;++i){
        csum[i]=csum[i-1]+(a[i]!=idx);
    }
    ll mi=ll(1e18+4);
    for(int i=1;i<=k;++i){
        int j=i;
        ll res=0;
        if(csum[j-1]>0)res++;
        for(;j+k-1<=n;j+=k){
            if(csum[j+k-1]-csum[j-1]>0)res++;
        }
        if(csum[n]-csum[j-1]>0)res++;
        mi=min(mi,res);
    }
    return mi;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    cin>>n>>k;
    ll ma=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    ll mi=ll(1e18+4);
    for(int i=1;i<=100;++i){
        mi=min(mi,f(i));
    }
    cout<<mi<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001],csum[100001];
ll dp[100001];
int c;
int n,k;
ll solve(ll idx){
    if(idx>=n)return 0;
    ll &res=dp[idx];
    if(res!=-1)return res;
    res=ll(1e18);
    if(a[idx]==c){
        res=min(res,solve(idx+1));
    }
    else{
      for(int j=0;j<k;++j){
        if(idx-j>=0){
            res=min(res,solve(idx+k)+1);
        }
      }
    }
    return res;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    cin>>n>>k;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    ll mi=ll(1e18);
    for(int i=1;i<100;++i){
          for(int j=0;j<n;++j)dp[j]=-1;
          c=i;
          mi=min(mi,solve(0));
    }
    cout<<mi<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001],csum[100001];
ll dp[100001];
int c;
int n,k;
ll solve(ll idx){
    if(idx>=n)return 0;
    ll &res=dp[idx];
    if(res!=-1)return res;
    res=ll(1e18);
    if(a[idx]==c){
        res=min(res,solve(idx+1));
    }
    else{
      for(int j=0;j<k;++j){
        if(idx-j>=0){
            res=min(res,solve(idx+k)+1);
        }
      }
    }
    return res;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    ll mi=ll(1e18);
    for(int i=1;i<100;++i){
          for(int j=0;j<n;++j)dp[j]=-1;
          c=i;
          mi=min(mi,solve(0));
    }
    cout<<mi<<"\n";

    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001],csum[100001],cnt[101];
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    int n,k;
    cin>>n>>k;
    ll ma=0,idx=0;
    for(int i=1;i<=n;++i)csum[i]=0;
    for(int i=1;i<=100;++i)cnt[i]=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        cnt[a[i]]++;
        if(cnt[a[i]]>ma){
            ma=cnt[a[i]];
            idx=a[i];
        }
    }
    for(int i=1;i<=n;++i){
        csum[i]=csum[i-1]+(a[i]!=idx);
    }
    ll mi=ll(1e18+4);
    for(int i=1;i<=k;++i){
        int j=i;
        ll res=0;
        if(csum[j-1]>0)res++;
        for(;j+k-1<=n;j+=k){
            if(csum[j+k-1]-csum[j-1]>0)res++;
        }
        if(csum[n]-csum[j-1]>0)res++;
        mi=min(mi,res);
    }
    cout<<mi<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lli;
typedef string st;
typedef pair<int , int> pi;
typedef pair<pair<int,int>,int> pii;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MP  make_pair
#define mem(a , v)  memset(a , v , sizeof(a))
#define all(v)  ((v).begin()), ((v).end())
#define MSB 63-__builtin_clzll
const ll MOD=998244353;
ll fix(ll x){
 return (x+MOD)%MOD;
}
ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         s%=MOD;
         if(y&1)
         s*=x;
         return s%MOD;
}
ll divide(ll a,ll b){
   return (a*power(b,MOD-2)%MOD)%MOD;
}
ll a[100001];
int c;
int n,k;
ll solve(ll idx){
    if(idx>=n)return 0;
    ll res=ll(1e18);
    if(a[idx]==c){
        res=min(res,solve(idx+1));
    }
    else{
      for(int j=0;j<k;++j){
        if(idx-j>=0){
            res=min(res,solve(idx+k)+1);
        }
      }
    }
    return res;
}
int main(){
    FastIO;
    int t;
    cin>>t;
    while(t--){
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    ll mi=ll(1e18);
    for(int i=1;i<=100;++i){
          c=i;
          mi=min(mi,solve(0));
    }
    cout<<mi<<"\n";
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n+1];
        ll cnt[101];
        memset(cnt, 0 , sizeof(cnt));
        for(int i = 1; i <= n;i++)  {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        ll mx = 0;
        for(int i = 1; i <= 100; i++)   {
            mx = max(mx, cnt[i]);
        }
        cout << (n - mx)/k + (ll)((n-mx)%k != 0) << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n];
        for(int i = 0; i  >n; i++) {
            cin >> arr[i];
        }
        ll ans = n;
        for(int col = 1; col <=  100; col++)  {
            ll curr = 0;
            for(int i = 0; i < n; i++)  {
                if(arr[i] != col)   {
                    i += k-1;
                    curr++;
                }
            }
            ans = min(ans, curr);
        }
        cout << ans << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n+1];
        for(int i = 1; i <= n;i++)  {
            cin >> arr[i];
        }
        ll   cnt[101], ans[101], last_idx[101];
        memset(cnt, 0, sizeof(cnt));
        memset(ans, 0, sizeof(ans));
        memset(last_idx, 0, sizeof(last_idx));
        for(int i = 1; i <= n; i++) {
            cnt[arr[i]] = 1;
            if(last_idx[arr[i]] +  1 == i)  {
                last_idx[arr[i]] = i;
            }
            else    {
                ll  val = i - last_idx[arr[i]] - 1;
                ans[arr[i]] += val/k + (ll)(val%k !=  0);
                last_idx[arr[i]] = i;
            }
            //cout << last_idx[2] << " "  << ans[2] << " \n";
        }
        ll mn = n;
        //cout << last_idx[2];
        for(int i = 1; i <=  100; i++)  {
            if(cnt[i] == 1)  {
                //cout << ans[2] << " ";
                if(last_idx[i] != n)    {
                    ll val = n - last_idx[i];

                    ans[i] += val/k + (ll)(val%k != 0);
                }
                //cout << ans[2] << "\n";
                //cout <<  i <<  " " << ans[i] << "\n";
                mn = min(mn, ans[i]);
            }

        }
        cout << mn << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n+1];
        for(int i = 1; i <= n;i++)  {
            cin >> arr[i];
        }
        ll   cnt[101], ans[101], last_idx[101];
        memset(cnt, 0, sizeof(cnt));
        memset(ans, 0, sizeof(ans));
        memset(last_idx, 0, sizeof(last_idx));
        for(int i = 1; i <= n; i++) {
            cnt[arr[i]] = 1;
            if(last_idx[arr[i]] +  1 == i)  {
                last_idx[arr[i]] = i;
            }
            else    {
                ll  val = i - last_idx[arr[i]] - 1;
                ans[arr[i]] += val/k + (ll)(val%k !=  0);
                last_idx[arr[i]] = i;
            }
        }
        ll mn = n;
        for(int i = 1; i <=  100; i++)  {
            if(cnt[i] == 1)  {
                if(last_idx[i] != n)    {
                    ll val = n - last_idx[arr[i]];
                    ans[i] += val/k + (ll)(val%k != 0);
                }
                mn = min(mn, ans[i]);
            }

        }
        cout << mn << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n+1];
        for(int i = 1; i <= n;i++)  {
            cin >> arr[i];
        }
        ll ans[101], last_idx[101];
        //memset(cnt, 0, sizeof(cnt));
        memset(ans, 0, sizeof(ans));
        memset(last_idx, 0, sizeof(last_idx));
        for(int i = 1; i <= n; i++) {
            if(last_idx[arr[i]] +  1 == i)  {
                last_idx[arr[i]] = i;
            }
            else    {
                ll  val = i - last_idx[arr[i]] - 1;
                ans[arr[i]] += val/k + (ll)(val%k !=  0);
                last_idx[arr[i]] = i;
            }
        }
        ll mn = n;
        for(int i = 1; i <=  100; i++)  {
            if(ans[i] > 0)  {
                if(last_idx[i] != n)    {
                    ll val = n - last_idx[arr[i]];
                    ans[i] += val/k + (ll)(val%k != 1);
                }
                mn = min(mn, ans[i]);
            }

        }
        cout << mn << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n+1];
        for(int i = 1; i <= n;i++)  {
            cin >> arr[i];
        }
        ll   cnt[101], ans[101], last_idx[101];
        memset(cnt, 0, sizeof(cnt));
        memset(ans, 0, sizeof(ans));
        memset(last_idx, 0, sizeof(last_idx));
        for(int i = 1; i <= n; i++) {
            cnt[arr[i]] = 1;
            if(last_idx[arr[i]] +  1 == i)  {
                last_idx[arr[i]] = i;
            }
            else    {
                ll  val = i - last_idx[arr[i]] - 1;
                ans[arr[i]] += val/k + (int)(val%k !=  0);
                last_idx[arr[i]] = i;
            }
            //cout << last_idx[2] << " "  << ans[2] << " \n";
        }
        ll mn = n;
        //cout << last_idx[2];
        for(int i = 1; i <=  100; i++)  {
            if(cnt[i] == 1)  {
                //cout << ans[2] << " ";
                if(last_idx[i] != n)    {
                    ll val = n - last_idx[i];

                    ans[i] += val/k + (int)(val%k != 0);
                }
                //cout << ans[2] << "\n";
                //cout <<  i <<  " " << ans[i] << "\n";
                mn = min(mn, ans[i]);
            }

        }
        cout << mn << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n+1];
        for(int i = 1; i <= n;i++)  {
            cin >> arr[i];
        }
        ll   cnt[101], ans[101], last_idx[101];
        memset(cnt, 0, sizeof(cnt));
        memset(ans, 0, sizeof(ans));
        memset(last_idx, 0, sizeof(last_idx));
        for(int i = 1; i <= n; i++) {
            cnt[arr[i]] = 1;
            if(last_idx[arr[i]] +  1 == i)  {
                last_idx[arr[i]] = i;
            }
            else    {
                ll  val = i - last_idx[arr[i]] - 1;
                ans[arr[i]] += val/k + (ll)(val%k !=  0);
                last_idx[arr[i]] = i;
            }
        }
        ll mn = n;
        for(int i = 1; i <=  100; i++)  {
            if(cnt[i] == 1)  {
                if(last_idx[i] != n)    {
                    ll val = n - last_idx[arr[i]];
                    ans[i] += val/k + (ll)(val%k != 1);
                }
                mn = min(mn, ans[i]);
            }

        }
        cout << mn << "\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, k;
        cin >> n >> k;
        ll arr[n];
        for(int i = 0; i < n; i++) {
            cin >> arr[i];
        }
        ll ans = n;
        for(int col = 1; col <=  100; col++)  {
            ll curr = 0;
            for(int i = 0; i < n; i++)  {
                if(arr[i] != col)   {
                    i += k-1;
                    curr++;
                }
            }
            ans = min(ans, curr);
        }
        cout << ans << "\n";

    }
}


  #include <bits/stdc++.h>
  #define endl "\n"
 /// #define int long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define MOD 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define clr(a,val) memset(a,val,sizeof(a))
  #define repp(i, a, b)  for(int i = a; i < b; i++)
  #define rep(i, a, b)  for(int i = a; i <= b; i++)
  #define pb push_back
  #define f first
  #define s second

  using namespace std;

  void solve(){
     int n, k;
     cin >> n >> k;
     map<int, int> mp;
     int a[n];
     for(int i = 0; i < n; i++)
     {
         cin >> a[i];
         mp[a[i]]++;
     }
     int col, maxi = 0;
     for(auto m : mp){
         if(m.s > maxi)
         {
             maxi = m.s;
             col = m.f;
         }
     }
     int cnt = 0;
     for(int i = 0; i < n; i++){
         if(a[i] != col){
             if(i + k  - 1 >= n)
             {
                 ++cnt;
                 break;
             }
             else{
                 ++cnt;
                 i = i + k - 1;
             }
         }
     }
     cout << cnt << endl;
  }

  int32_t main()
  {
    int T = 1;  cin >> T;
    for(int t=1;t<=T;t++)
    {
      //cout<<"Case #"<<t<<": ";
      solve();

    }

    return 0;
  }


for _ in range(int(input())):
	n, k = list(map(int, input().split()))
	if k > n:
		print(k - n)
	elif k == n:
		print(0)
	else:
		if (k == 0) and (n % 2 == 0):
			print(0)
		else:
			print(min(abs(n - k * 2), abs(n - k)))


for w in range(int(input())):
    n,k=tuple(map(int,input().split()))
    if(n==k):
        print(0)
    elif(k==0):
        if(n%2==0):
            print(0)
        else:
            print(1)
    else:
        print(abs(n-k))


for w in range(int(input())):
    n,k=tuple(map(int,input().split()))
    if(n==k):
        print(0)
    elif(k==0):
        if(n%2==0):
            print(0)
        else:
            print(1)
    elif(n<k):
        print(abs(n-k))
    else:
        print(0)


for w in range(int(input())):
    n,k=tuple(map(int,input().split()))
    if(n==k):
        print(0)
    elif(k==0):
        if(n%2==0):
            print(0)
        else:
            print(1)
    elif(n<k):
        print(abs(n-k))
    else:
        if(n%2==0):
            if(k%2!=0):
                print(0)
            else:
                print(1)
        else:
            if(k%2==0):
                print(0)
            else:
                print(1)


for w in range(int(input())):
    n,k=tuple(map(int,input().split()))
    if(n==k):
        print(0)
    elif(k==0):
        if(n%2==0):
            print(0)
        else:
            print(1)
    elif(n<k):
        print(abs(n-k))
    else:
        if(n%2==0):
            if(k%2!=0):
                print(1)
            else:
                print(0)
        else:
            if(k%2==0):
                print(1)
            else:
                print(0)


for _ in range(int(input())):
    n,k = map(int, input().split())
    if n > k and n>1:
        print(2*k)
    else:
        print(abs(n-k))


for _ in range(int(input())):
    n,k = map(int, input().split())
    if n > k:
        print(2*k)
    else:
        print(abs(n-k))


for _ in range(int(input())):
    n,k = map(int, input().split())
    if n >= k:
        if n%2 == k%2:
            print(0)
        else:
            print(1)
    else:
        print(abs(n-k))


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	if b==a:
		print(0)
	elif b>a:
		print(abs(b-a))
	else:
		x=mt.ceil((b+a)/2)
		#print("adsf",x)
		if x<a:
			print(0)
		else:
			print(x)


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	temp=abs(1-(a-1))
	if a==1 and b==0:
		print(1)
		continue
	if b<=temp:
		print(0)
	else:
		print(abs(a-b))


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	temp=abs(1-(a-1))
	if a==0:
		if b%2==0:
			if a<b:
				print(b)
			else:
				print(0)
		else:
			print(1)
		continue
	if a%2==0 and b%2==0:
		print(0)
	elif a%2==0  and b%2:
		print(abs(b-a))
	elif a%2 and b%2:
		print(0)
	elif a%2 and b%2==0:
		print(abs(a-b))


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	temp=abs(1-(a-1))
	if a==0:
		if b%2==0:
			print(b)
		else:
			print(1)
		continue
	if a%2==0 and b%2==0:
		print(0)
	elif a%2==0  and b%2:
		print(abs(b-a))
	elif a%2 and b%2:
		print(0)
	elif a%2 and b%2==0:
		print(abs(a-b))


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	n,k=I()
	if k>n:
		print(abs(n-k))
	else:
		print(0 if n%2==k%2 else 1)


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	if b==a:
		print(0)
	elif b>a:
		print(abs(b-a))
	else:
		print(mt.ceil(b+a/2))


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	temp=abs(1-(a-1))
	if a==0:
		print(b)
		continue
	if a%2==0 and b%2==0:
		print(0)
	elif a%2==0  and b%2:
		print(abs(b-a))
	elif a%2 and b%2:
		print(0)
	elif a%2 and b%2==0:
		print(abs(a-b))


import sys,math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	a,b=I()
	if b==a:
		print(0)
	elif b>a:
		print(abs(b-a))
	else:
		x=mt.ceil(b+a/2)
		#print("adsf",x)
		if x<a:
			print(0)
		else:
			print(x)


for _ in range(int(input())):
    A, diff = map(int, input().split())
    if diff>= A:
        print(diff - A)
    else:
        if diff == 0:
            if A&1:
                print(1)
            else:
                print(0)
        else:
            if diff<=A:
                print(0)
            else:
                print(abs(diff - A))


for _ in range(int(input())):
    A, diff = map(int, input().split())
    if diff> 0:
        print(abs(diff - A))
    else:
        if A&1:
            print(1)
        else:
            print(0)


for _ in range(int(input())):
    A, diff = map(int, input().split())
    if diff>= A:
        print(diff - A)
    else:
        if diff == 0:
            if A&1:
                print(1)
            else:
                print(0)
        else:
            ans = min(abs(diff - A), abs(2*diff - A) )
            print(ans)


for _ in range(int(input())):
    A, diff = map(int, input().split())
    if diff >= A:
        print(abs(diff - A))
    else:
        if A&1:
            print(1)
        else:
            print(0)


for _ in range(int(input())):
    A, diff = map(int, input().split())
    if diff >= A:
        print(abs(diff - A))
    else:
        if (A&1)^(diff&1):
            print(1)
        else:
            print(0)


t= int(input())
for i in range(t):
    n,k = map(int,input().split())
    if(n==k):
        print(0)
    elif(n<k):
        print(k-n)
    else:

        if(n%2 == 0 and k%2 == 0):
            print(0)
        else:
            print(1)


t= int(input())
for i in range(t):
    n,k = map(int,input().split())
    if(n==k):
        print(0)
    elif(n<k):
        print(k-n)
    else:
        if(k>0):
            print(n-k)
        else:
            if(n%2 == 0):
                print(0)
            else:
                print(1)


t= int(input())
for i in range(t):
    n,k = map(int,input().split())
    if(n==k):
        print(0)
    elif(n<k):
        print(k-n)
    else:

        if(n%2 == k%2):
            print(0)
        else:
            print(1)


for _ in range(int(input())):
    n,k=map(int, input().split())
    if k>n:
        print(abs(k-n))
    elif k%2==0 and n%2==0:
        print(0)
    else:
        print(1)


for _ in range(int(input())):
    n,k=map(int, input().split())
    val1=k-n
    if n==k:
        print(0)
    elif k==0 and n%2==0:
        print(0)
    elif k==0 and n%2!=0:
        print(1)
    elif n==0:
        print(k)
    else:
        print(abs(k-n))


for _ in range(int(input())):
    n,k=map(int, input().split())
    val1=k-n
    if n==k:
        print(0)
    elif k==0:
        print(1)
    elif n==0:
        print(k)
    else:
        print(abs(k-n))


for _ in range(int(input())):
    n,k=map(int, input().split())
    if n==k:
        print(0)
    elif k==0 and n%2==0:
        print(0)
    elif k==0 and n%2==1:
        print(1)
    elif k>n:
        print(abs(k-n))
    elif k<n and n%2==0:
        print(0)
    else:
        print(1)


for _ in range(int(input())):
    n,k=map(int, input().split())
    val1=k-n
    if val1>0:
        print(val1)
    else:
        print(0)


for _ in range(int(input())):
    n,k=map(int, input().split())
    if k>n:
        print(abs(k-n))
    elif k%2==n%2:
        print(0)
    else:
        print(1)


for _ in range(int(input())):
    n,k=map(int, input().split())
    if n==k:
        print(0)
    elif k==0 and n%2==0:
        print(0)
    elif k==0 and n%2==1:
        print(1)
    elif k>n:
        print(abs(k-n))
    else:
        print(1)


def distance_and_axis(n: int, k: int) -> int:
	# All the 0 cases to prevent division by 0
	if k == 0 and n % 2 == 0:
		return 0
	elif k == 0:
		return 1
	elif n == 0:
		return k

	if k > n:
		return k % n
	else:
		return round(1 / (k / n)) * k - n

if __name__ == '__main__':
	t = int(input())

	for _ in range(t):
		n, k = map(int, input().split(' '))

		print(distance_and_axis(n, k))


def distance_and_axis(n: int, k: int) -> int:
	if n > k and n % 2 == 1:
		return 1
	elif n > k and n % 2 == 0:
		return 0

	return k - n

if __name__ == '__main__':
	t = int(input())

	for _ in range(t):
		n, k = map(int, input().split(' '))

		print(distance_and_axis(n, k))


def distance_and_axis(n: int, k: int) -> int:
	# All the 0 cases to prevent division by 0
	if k == 0 and n % 2 == 0:
		return 0
	elif k == 0:
		return 1
	elif n == 0:
		return k

	if k > n:
		return k - n

	b_prelim = (n - k) / 2

	if b_prelim.is_integer():
		return 0
	else:
		return 1

if __name__ == '__main__':
	t = int(input())

	for _ in range(t):
		n, k = map(int, input().split(' '))

		print(distance_and_axis(n, k))


def distance_and_axis(n: int, k: int) -> int:
	# All the 0 cases to prevent division by 0
	if k == 0 and n % 2 == 0:
		return 0
	elif k == 0:
		return 1
	elif n == 0:
		return k

	if k > n:
		return k % n
	else:
		return abs(round(1 / (k / n)) * k - n)

if __name__ == '__main__':
	t = int(input())

	for _ in range(t):
		n, k = map(int, input().split(' '))

		print(distance_and_axis(n, k))


for _ in range(int(input())):
    n,k = map(int,input().split())
    if(n==k or abs((n//2)-(n-n//2))==k):
        print(0)
    else:
        print(abs(k-n))


for _ in range(int(input())):
    n,k = map(int,input().split())
    if(k<=n):
        if((n-k)%2==0):
            print(0)
        else:
            print(1)
    else:
        print(k-n)


for _ in range(int(input())):
    n,k = map(int,input().split())
    ans1 = abs(n-k) if(n-k<0) else 0
    ans1 += (n+abs(n-k))%2
    ans2 = (n+k)%2
    print(max(ans1,ans2))


for _ in range(int(input())):
    n,k = map(int,input().split())
    ans1 = 0
    ans2 = 0
    a = n
    while((a-k)%2 or a-k<0):
        a+=1
        ans1+=1
    while((n+k)%2 or n+k<0):
        n-=1
        ans2+=1
    print(max(ans1,ans2))


for _ in range(int(input())):
    n,k = map(int,input().split())
    if(n==k or (n%2==0 and k==0)):
        print(0)
    else:
        print(abs(n-k))


for _ in range(int(input())):
    n,k = map(int,input().split())
    if(n==k or abs((k+n//2)-(n-k-n//2))==k):
        print(0)
    else:
        print(abs(k-n))


for t in range(int(input())):
    n, k = map(int, input().split())
    if n == k:
        print(0)
    elif n < k:
        print(abs(k-n))
    else:
        if k == 0:
            if n % 2 == 0:
                print(0)
            else:
                print(1)
        else:
            if (n-k) > 1:
                print(0)
            else:
                print(1)


for t in range(int(input())):
    n, k = map(int, input().split())
    if n == k:
        print(0)
    elif n < k:
        print(abs(k-n))
    else:
        if n % 2 == 0:
            print(0)
        else:
            print(1)


for t in range(int(input())):
    n, k = map(int, input().split())
    if n == k:
        print(k)
    elif n < k:
        print(abs(k-n))
    else:
        if (n-1) > k:
            print(0)
        else:
            print(1)


for t in range(int(input())):
    n, k = map(int, input().split())
    if n == k:
        print(0)
    elif n < k:
        print(abs(k-n))
    else:
        if n > 1:
            print(0)
        else:
            print(1)


for t in range(int(input())):
    n, k = map(int, input().split())
    if n == k:
        print(0)
    elif n < k:
        print(abs(k-n))
    else:
        if (n-1) > k:
            print(0)
        else:
            print(1)


for t in range(int(input())):
    n, k = map(int, input().split())
    if n <= k:
        print(k-n)
    else:
        if n % 2 == 0:
            print(0)
        else:
            if k == 0:
                print(1)
            else:
                print(0)


for t in range(int(input())):
    n, k = map(int, input().split())
    if n <= k:
        print(k-n)
    else:
        a = n-k
        print(a % 2)


import sys
input=sys.stdin.buffer.readline
inin=lambda: int(input())
inar=lambda: list(map(int,input().split()))
inst=lambda: input().decode().rstrip('\n\r')
#INF=float('inf')
#from collections import deque as que, defaultdict as vector, Counter
#from bisect import bisect
#from heapq import heapify, heappush as hpush, heappop as hpop
'''from types import GeneratorType
def recursive(f, stack=[]):
  def wrappedfunc(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    else:
      to = f(*args, **kwargs)
      while True:
        if type(to) is GeneratorType:
          stack.append(to); to = next(to)
        else:
          stack.pop()
          if not stack: break
          to = stack[-1].send(to)
      return to
  return wrappedfunc'''

_T_=inin()
for _t_ in range(_T_):
    n,k=inar()
    if k>n:
        print(k-n)
    else:
        if k%2:
            if n%2:
                print(0)
            else:
                print(1)
        else:
            if n%2:
                print(1)
            else:
                print(0)