#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		unordered_map<int,int> mp;
		for(int i=0;i<n;i++)
		 {
		 	cin>>arr[i];
		 	mp[arr[i]]++;
		 }
		 int mxc=0;
		 for(auto x:mp)
		 {
		 	if(x.second>mxc)
		 	 mxc=x.first;
		 }
		 int count=0;
		 for(int i=0;i<n;)
		 {
		 	if(arr[i]!=mxc)
		 	 {
		 	 	count++;
		 	 	i=i+k;
			 }
			 else
			  i++;
		 }
		 cout<<count<<endl;

	}
	return 0;
}


#include<iostream>
#include<unordered_set>
#include<limits.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		unordered_set<int> s;
		for(int i=0;i<n;i++)
		 {
		 	cin>>arr[i];
		 	s.insert(arr[i]);
		 }
		 int res=INT_MAX;
		 for(auto x:s)
		 {
		  int count=0;
		 for(int i=0;i<n;)
		 {
		 	if(arr[i]!=x)
		 	 {
		 	 	count++;
		 	 	i=i+k;
			 }
			 else
			  i++;
		 }
		 res=min(res,count);
	   }
	   cout<<res<<endl;
	}
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		unordered_map<int,int> mp;
		for(int i=0;i<n;i++)
		 {
		 	cin>>arr[i];
		 	mp[arr[i]]++;
		 }
		 int mxc=0,e;
		 for(auto x:mp)
		 {
		 	if(x.second>mxc)
		 	 {
			  mxc=x.second;
			  e=x.first;
		    }
		 }
		 int count=0;
		 for(int i=0;i<n;)
		 {
		 	if(arr[i]!=e)
		 	 {
		 	 	count++;
		 	 	i=i+k;
			 }
			 else
			  i++;
		 }
		 cout<<count<<endl;

	}
	return 0;
}


#include<iostream>
#include<unordered_set>
#include<limit.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		unordered_set<int> s;
		for(int i=0;i<n;i++)
		 {
		 	cin>>arr[i];
		 	s.insert(arr[i]);
		 }
		 int res=INT_MAX;
		 for(auto x:s)
		 {
		  int count=0;
		 for(int i=0;i<n;)
		 {
		 	if(arr[i]!=x)
		 	 {
		 	 	count++;
		 	 	i=i+k;
			 }
			 else
			  i++;
		 }
		 res=min(res,count);
	   }
	}
	return 0;
}


#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		unordered_map<int,int> mp;
		for(int i=0;i<n;i++)
		 {
		 	cin>>arr[i];
		 	mp[arr[i]]++;
		 }
		 int mxc=0;
		 for(auto x:mp)
		 {
		 	if(x.second>mxc)
		 	 mxc=x.first;
		 }
		 int count=0;
		 for(int i=0;i<n;)
		 {
		 	if(arr[i]!=mxc)
		 	 {
		 	 	count++;
		 	 	i=i+k;
			 }
			 else
			  i++;
		 }
		 cout<<count<<" ";

	}
	return 0;
}


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

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		for(int i=0;i<n;i++)
			cin>>arr[i];
		int mini=n;
		for(int i=1;i<=100;i++)
		{
			int ans=0;
			int cnt=0;
			int val=0;
			for(int j=0;j<n;j++)
			{
				if(arr[j]==i && val<k && val>0)
				{
					val++;
				}
				else if(arr[j]!=i)
				{
					cnt++;
					val++;
				}

				if(val==k)
				{
					if(cnt>0)
						ans++;
					cnt=0;
					val=0;
				}
				//cout<<i<<" "<<val<<" "<<cnt<<" "<<ans<<endl;
			}
			if(cnt>0)
			    ans++;
			mini=min(ans,mini);
		}
		cout<<mini<<endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		vector<int> color(101, 0);
		vector<int> maxi;
		int n, k;
		cin >> n >> k;
		vector<int>v(n);
		for (int j = 0; j < n; j++) {
			cin >> v[j];
			color[v[j]]++;
		}
		int col = 0;
		for (int j = 1; j < color.size(); j++) {
			if (color[j] > color[col])col = j;
		}
		for (int j = 0; j < color.size(); j++) {
			if (color[j] == color[col])maxi.push_back(j);
		}
		int mini = 10000000;
		for (int ii = 1; ii <= 100; ii++) {

			int cnt = 0;
			int j = 0;
			while (j < v.size()) {
				if (v[j] == ii)j++;
				else {
					cnt++;
					j += k;
				}
			}
			if (cnt < mini)mini = cnt;
		}
		cout << mini << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		vector<int> color(101, 0);
		vector<int> maxi;
		int n, k;
		cin >> n >> k;
		vector<int>v(n);
		for (int j = 0; j < n; j++) {
			cin >> v[j];
			color[v[j]]++;
		}
		int col = 0;
		for (int j = 1; j < color.size(); j++) {
			if (color[j] > color[col])col = j;
		}
		for (int j = 0; j < color.size(); j++) {
			if (color[j] == color[col])maxi.push_back(j);
		}
		int mini = 10000000;
		for (int ii = 0; ii < maxi.size(); ii++) {

			int cnt = 0;
			int j = 0;
			while (j < v.size()) {
				if (v[j] == maxi[ii])j++;
				else {
					cnt++;
					j += k;
				}
			}
			if (cnt < mini)mini = cnt;
		}
		cout << mini << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		vector<int> color(101, 0);
		int n, k;
		cin >> n >> k;
		vector<int>v(n);
		for (int j = 0; j < n; j++) {
			cin >> v[j];
			color[v[j]]++;
		}
		int col = 0;
		for (int j = 1; j < color.size(); j++) {
			if (color[j] > color[col])col = j;
		}
		int cnt = 0;
		int j = 0;
		while (j < v.size()) {
			if (v[j] == col)j++;
			else {
				cnt++;
				j += k;
			}
		}
		cout << cnt << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long

int32_t main()
{ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

    int t;
    cin>>t;
    while(t--)
    {
        map<int,int>s;

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

     int a[n];
     int c=0,d;
    unordered_set<int>w;
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
         w.insert(a[i]);

     }

    // cout<<d<<": ";
     int sum=0,l=INT_MAX;
     for(auto it:w)
     {
            sum=0;
     for(int i=0;i<n;i++)
     {
         int j=i,z=0;
         for(j;j<j+k;j++)
         {
             if(a[j]==it)
                i++;
             if(j==n)
                break;
             if(a[j]!=it)
             {
                 z++;
                 break;
             }
         }
         if(j==n)
         {
             if(z!=0)
                sum++;
         }
         else if(z!=0)
           {

            sum++;
     //       cout<<sum<<"-"<<j<<" ";
           }
         i+=k-1;

     }
     l=min(sum,l);
     }
     cout<<l<<"\n";

    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int arr[n]; map<int,int>mp;
        for(int i=0;i<n;i++){cin>>arr[i];mp[arr[i]]++;}

          if(mp.size() == 1)
          {cout<<"0\n";continue;}

        if(k==n)
        {
          if(mp.size() > 1)
          {cout<<"1\n";continue;}
        }
      int ANS=n;
       for(auto it=mp.begin();it!=mp.end();it++)
{
        int i=0,ans=0,ele=it->first;

        while(i<n)
        {
          if(arr[i]==ele)
          {i++;
          continue;}

          i+=k;
          ans++;
        }
        ANS=min(ANS,ans);
}

        cout<<ANS<<"\n";
    }
    return 0;
}


/*
   Three things which are very important --
   Violence - Speed - Momentum
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define setbits(x)      __builtin_popcountll(x)
#define leadzero(x)     __builtin_clz(x)
#define trailzero(x)    __builtin_ctz(x)
#define bitsparity(x)   __builtin_parity(x)
#define mod             1000000007
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll              long long
#define pre(y,x)        fixed<<setprecision(y)<<x
#define dbg1(x)         cerr << "|" << #x << ": " << (x) << "|\n";
#define dbg2(x,y)       cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|\n";
#define dbg3(x,y,z)     cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|" << #z << ": " << (z) << "|\n";
#define ff              first
#define ss              second
#define pb              push_back
#define eb              emplace_back
#define popb            pop_back
#define endl            '\n'
#define all(v)          v.begin(), v.end()
#define sz(x)           ((int)((x).size()))
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
ll power(ll a, ll b) {
	if(b<0) return 1;
	ll res=1;
	while(b) {
		if(b&1)
			res = (res*a);//%mod;
		a = (a*a);//%mod;
		b >>= 1;
	}
	return res;
}
bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
const int inf = 1e9;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
char MV[] = {'U', 'R', 'D', 'L'};
//integer to char always remember (char+'0')
const double pi = acos(-1);
const ll INF = 1e18;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline void solve() {
	int n, k;
	cin >> n >> k;

	int a[n];
	for(int i=0; i<n; ++i) {
		cin >> a[i];
	}
	int ans=n;

	for(int c=1; c<=100; ++c) {
		int i=0, sum=0;
		while(i<n) {
			if(a[i] == c) {
				i++;
				continue;
			}
			sum++;
			i += k;
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}
int main() {
	FIO;
	int t; cin >> t;
	while(t--)
	solve();
}
/*
1
13 4
2 2 2 1 2 1 2 1 2 1 1 1 1
*/


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		vector<int> a(n);
		set<int> cc;
		for (int& x : a) {
			cin >> x;
			cc.insert(x);
		}

		int ans = INT_MAX;
		for (auto& c : cc) {
			int ans_cur = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != c) {
					int j = i;
					while (j < n && a[j] != c) j++;
					ans_cur += ((j - i) + k - 1) / k;
					if ((j - i) % k != 0) {
						int h = k - ((j - i) % k);
						j += h;
					}
					i = j;
				}
			}
			ans = min(ans_cur, ans);
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

// #define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t; cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		vector<int> a(n);
		map<int, int> mp;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			mp[a[i]]++;
		}

		int ans = 0;
		int color = max_element(mp.begin(), mp.end())->first;
		int l = 0, r = 0;
		while (r != n) {
			int mn = n;
			int cur = (a[r] == color ? 1 : 0);
			while (r < n && r - l < k) {
				if (a[r] != color) mn = min(r, mn);
				r++;
			}

			if (mn == l) {
				ans++;
				l = r;
			}
			else if (mn == n) {
				l = r;
			} else {
				l = mn;
				r = mn;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		vector<int> a(n);
		set<int> cc;
		for (int& x : a) {
			cin >> x;
			cc.insert(x);
		}

		int ans = INT_MAX;
		for (auto& c : cc) {
			int ans_cur = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != c) {
					int j = i;
					while (j < n && a[j] != c) j++;
					ans_cur += ((j - i) + k - 1) / k;
					if ((j - i) % k != 0) {
						int h = k - ((j - i) % k) - 1;
						j += h;
					}
					i = j;
				}
			}
			ans = min(ans_cur, ans);
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;
        }

        int ans = 0;
        int color = max_element(mp.begin(), mp.end())->first;
        int l = 0, r = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != color) {
				int j = i;
				while (j < n && a[j] != color) j++;
				ans += ((j - i) + k - 1) / k;
				i = j;
			}
		}
        cout << ans << "\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
		map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
			mp[a[i]]++;
	    }

        int ans = INT_MAX;
		for (int cc = 1; cc <= 100; cc++) {
			int color = cc;
			int cur_ans = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != color) {
					int j = i;
					while (j < n && a[j] != color) j++;
					cur_ans += ((j - i) + k - 1) / k;
					i = j + (j - i) % k;
				}
			}
			ans = min(cur_ans, ans);
		}
        cout << ans << "\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
		map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
			mp[a[i]]++;
	    }

		if (k == n) {
			cout << (mp.size() > 1 ? 1 : 0) << "\n";
			continue;
		}
        int ans = INT_MAX;
		for (int cc = 1; cc <= 100; cc++) {
			int color = cc;
			int cur_ans = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != color) {
					int j = i;
					while (j < n && a[j] != color) j++;
					cur_ans += ((j - i) + k - 1) / k;
					i = j;
				}
			}
			ans = min(cur_ans, ans);
		}
        cout << ans << "\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
	    }

        int ans = INT_MAX;
		for (int cc = 1; cc <= 100; cc++) {
			int color = cc;
			int cur_ans = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != color) {
					int j = i;
					while (j < n && a[j] != color) j++;
					cur_ans += ((j - i) + k - 1) / k;
					i = j + (k - (j - i) % k);
				}
			}
			ans = min(cur_ans, ans);
		}
        cout << ans << "\n";
    }
	return 0;
}


include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;
        }

        int ans = INT_MAX;
		for (auto it : mp) {
			int color = it.first;
			int cur_ans = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != color) {
					int j = i;
					while (j < n && a[j] != color) j++;
					cur_ans += ((j - i) + k - 1) / k;
					i = j;
				}
			}
			ans = min(cur_ans, ans);
		}
        cout << ans << "\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;
        }

        int ans = INT_MAX;
		for (auto it : mp) {
			int color = it.first;
			int cur_ans = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] != color) {
					int j = i;
					while (j < n && a[j] != color) j++;
					cur_ans += ((j - i) + k - 1) / k;
					i = j;
				}
			}
			ans = min(cur_ans, ans);
		}
        cout << ans << "\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

// #define int long long

int32_t main() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        map<int, int> mp;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;
        }

        int ans = 0;
        int color = max_element(mp.begin(), mp.end())->first;
        int l = 0, r = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != color) {
				int j = i;
				while (j < n && a[j] != color) j++;
				ans += ((j - i) + k - 1) / k;
				i = j;
			}
		}
        cout << ans << "\n";
    }
	return 0;
}


// yoji_20 ======= 20-11-30 10:33:13 =======
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//=======debugging=======

#define deb(x) cout<<#x<<" = "<<x<<endl
#define debb(x,y) cout<<#x<<" = "<<x<<","<<#y<<" = "<<y<<endl

//=======loops=======

#define foe(a,b) for(auto a : b)
#define foer(a,b) for(auto &a : b)
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define rof(i,a,b) for(int i=(a);i>=(b);i--)

//=======Get data into ds=======

#define foein(x) foer(a,x)cin>>a// array/vector input
#define getset(x,n) fo(i,0,n-1){ int el;si(el);x.insert(el);}
#define getmat(x,n,m)  fo(i,0,n-1){vi tmp(m);foein(tmp);x.push_back(tmp);}

//=======print data of ds=======

#define print(x) foe(a,x)cout<<a<<" ";cout<<endl //array//vector output
#define putmat(x) foe(a,x){foe(b,a)cout<<b<<" ";cout<<endl;}

//=======sorting=======

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sall(x) sort(all(x))
#define sallr(x) sort(allr(x))

//=======STL aliases=======

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef set<int> si;
typedef set<pii> spii;
typedef vector<pii> vpii;

//=======some more STL aliases=======

#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second

//=======declare and define=======
#define cint(x) int x;cin>>x
#define vint(v,n) vi v(n);foein(v)

void solve(){

	cint(n);cint(k);
	vint(v,n);
	int ans = (int)INT_MAX;
	fo(i,1,100){
		int cur_ans = 0;
		int j = 0;
		while(j<n)
			if(v[j]==v[i])j++;
			else {cur_ans++;j+=k;}
		ans = min(ans,cur_ans);
	}
	cout<<ans<<endl;

}

signed main(void){
	fastio;
	#define T
	//#define G
	#ifdef T
		int t;
		cin>>t;
		fo(test,1,t){
			solve();
		}
	#else
		#ifdef G
			int t;
			cin>>t;
			fo(test,1,t){
				cout<<"Case #"<<test<<": ";
				solve();
			}
		#else
			solve();
		#endif
	#endif
return 0;
}


// yoji_20 ======= 20-11-30 10:33:13 =======
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//=======debugging=======

#define deb(x) cout<<#x<<" = "<<x<<endl
#define debb(x,y) cout<<#x<<" = "<<x<<","<<#y<<" = "<<y<<endl

//=======loops=======

#define foe(a,b) for(auto a : b)
#define foer(a,b) for(auto &a : b)
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define rof(i,a,b) for(int i=(a);i>=(b);i--)

//=======Get data into ds=======

#define foein(x) foer(a,x)cin>>a// array/vector input
#define getset(x,n) fo(i,0,n-1){ int el;si(el);x.insert(el);}
#define getmat(x,n,m)  fo(i,0,n-1){vi tmp(m);foein(tmp);x.push_back(tmp);}

//=======print data of ds=======

#define print(x) foe(a,x)cout<<a<<" ";cout<<endl //array//vector output
#define putmat(x) foe(a,x){foe(b,a)cout<<b<<" ";cout<<endl;}

//=======sorting=======

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sall(x) sort(all(x))
#define sallr(x) sort(allr(x))

//=======STL aliases=======

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef set<int> si;
typedef set<pii> spii;
typedef vector<pii> vpii;

//=======some more STL aliases=======

#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second

//=======declare and define=======
#define cint(x) int x;cin>>x
#define vint(v,n) vi v(n);foein(v)

void solve(){

	cint(n);cint(k);
	vint(v,n);
	int ans = (int)INT_MAX;
	fo(i,1,100){
		int cur_ans = 0;
		int j = 0;
		while(j<n)
			if(v[j]==i)j++;
			else {cur_ans++;j+=k;}
		ans = min(ans,cur_ans);
	}
	cout<<ans<<endl;

}

signed main(void){
	fastio;
	#define T
	//#define G
	#ifdef T
		int t;
		cin>>t;
		fo(test,1,t){
			solve();
		}
	#else
		#ifdef G
			int t;
			cin>>t;
			fo(test,1,t){
				cout<<"Case #"<<test<<": ";
				solve();
			}
		#else
			solve();
		#endif
	#endif
return 0;
}


// yoji_20 ======= 20-11-30 10:33:13 =======
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//=======debugging=======

#define deb(x) cout<<#x<<" = "<<x<<endl
#define debb(x,y) cout<<#x<<" = "<<x<<","<<#y<<" = "<<y<<endl

//=======loops=======

#define foe(a,b) for(auto a : b)
#define foer(a,b) for(auto &a : b)
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define rof(i,a,b) for(int i=(a);i>=(b);i--)

//=======Get data into ds=======

#define foein(x) foer(a,x)cin>>a// array/vector input
#define getset(x,n) fo(i,0,n-1){ int el;si(el);x.insert(el);}
#define getmat(x,n,m)  fo(i,0,n-1){vi tmp(m);foein(tmp);x.push_back(tmp);}

//=======print data of ds=======

#define print(x) foe(a,x)cout<<a<<" ";cout<<endl //array//vector output
#define putmat(x) foe(a,x){foe(b,a)cout<<b<<" ";cout<<endl;}

//=======sorting=======

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sall(x) sort(all(x))
#define sallr(x) sort(allr(x))

//=======STL aliases=======

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef set<int> si;
typedef set<pii> spii;
typedef vector<pii> vpii;

//=======some more STL aliases=======

#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second

//=======declare and define=======
#define cint(x) int x;cin>>x
#define vint(v,n) vi v(n);foein(v)

void solve(){

	cint(n);
	vint(v,n);
	int ans = INT_MAX;
	fo(i,1,100){
		int cur_ans = 0;
		int j = 0;
		while(j<n)
			if(v[j]==v[i])j++;
			else {cur_ans++;j+=k;}
		ans = min(ans,cur_ans);
	}
	cout<<ans<<endl;

}

signed main(void){
	fastio;
	#define T
	//#define G
	#ifdef T
		int t;
		cin>>t;
		fo(test,1,t){
			solve();
		}
	#else
		#ifdef G
			int t;
			cin>>t;
			fo(test,1,t){
				cout<<"Case #"<<test<<": ";
				solve();
			}
		#else
			solve();
		#endif
	#endif
return 0;
}


#include<bits/stdc++.h>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#define int long long
#define sz size()
#define S second
#define F first
#define pb push_back
#define all(x) (x).begin(),(x).end()

main(){
    int q;
    cin>>q;
    while(q--){
        int n,k;
        cin>>n>>k;
        int a[n+1],ans=0;
        set<int>st;
        map<int,int>mp;
        for(int i = 1 ; i <= n; ++i){
            cin >> a[i];
            st.insert(a[i]);
            mp[a[i]]++;
        }
        int mx=-1,lol;
        for(auto it:st){
            if(mp[it]>mx){
                lol=it;
                mx=mp[it];
            }
        }
        for(int i = 1 ; i <= n;++i){
            if(a[i]!=lol){
                int l=i,r=i;
                while(a[r]!=lol&&r <= n){
                    r++;
                }
//                cout<<l<<' ' << r <<"\n";
                ans+=(r-l)/k+((r-l)%k!=0);
                i=r;
            }
        }
        cout<<ans<<'\n';
    }
}


#include<bits/stdc++.h>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#define ll long long
#define sz size()
#define S second
#define F first
#define pb push_back
#define all(x) (x).begin(),(x).end()

main(){
    int q;
    cin>>q;
    while(q--){
        int n,k;
        cin>>n>>k;
        int a[n+1],ans=0;
        set<int>st;
        map<int,int>mp;
        for(int i = 1 ; i <= n; ++i){
            cin >> a[i];
            st.insert(a[i]);
            mp[a[i]]++;
        }
        vector<int>v[101];
        int mx=-1;
        int ans1=10000000;
        for(auto it:st){
            ans = 0;
            for(int i = 1 ; i <= n;++i){
                if(a[i]!=it){
                    int l=i,r=i;
                    ans++;
                    i += k-1;
                }
            }
            ans1=min(ans,ans1);
        }
        cout<<ans1<<'\n';
    }
}


#include<bits/stdc++.h>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#define int long long
#define sz size()
#define S second
#define F first
#define pb push_back
#define all(x) (x).begin(),(x).end()

main(){
    int q;
    cin>>q;
    while(q--){
        int n,k;
        cin>>n>>k;
        int a[n+1],ans=0;
        set<int>st;
        map<int,int>mp;
        for(int i = 1 ; i <= n; ++i){
            cin >> a[i];
            st.insert(a[i]);
            mp[a[i]]++;
        }
        int mx=-1,lol;
        for(auto it:st){
            if(mp[it]>mx){
                lol=it;
                mx=mp[it];
            }
        }
        for(int i = 1 ; i <= n;++i){
            if(a[i]!=lol){
                int l=i,r=i;
                ans++;
                i+=k-1;
            }
        }
        cout<<ans<<'\n';
    }
}


#include<bits/stdc++.h>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#define ll long long
#define sz size()
#define S second
#define F first
#define pb push_back
#define all(x) (x).begin(),(x).end()

main(){
    int q;
    cin>>q;
    while(q--){
        int n,k;
        cin>>n>>k;
        int a[n+1],ans=0;
        set<int>st;
        map<int,int>mp;
        for(int i = 1 ; i <= n; ++i){
            cin >> a[i];
            st.insert(a[i]);
            mp[a[i]]++;
        }
        vector<int>v[101];
        int mx=-1,lol;
        for(auto it:st){
            if(mp[it] == mx){
                v[mx].pb(it);
            }
            if(mp[it]>mx){
                lol=it;
                mx=mp[it];
                v[mx].pb(it);
            }

        }
        if(v[mx].size()==n){
            cout<<(n-1)/k+((n-1)%k!=0)<<'\n';
            continue;
        }
        int ans1=10000000;
        for(int it = 0;it < v[mx].size();++it){
            ans = 0;
            for(int i = 1 ; i <= n;++i){
                if(a[i]!=v[mx][it]){
    //                int l=i,r=i;
                    ans++;
                    i += k-1;
                }
            }
            ans1=min(ans,ans1);
        }
        cout<<ans1<<'\n';
    }
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
    int t,n,k,i,j,a[100010];
    scanf("%d",&t);
    while(t--)
    {
        int minn=inf,sum;
        scanf("%d%d",&n,&k);
        for(i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(i=1; i<=100; i++)
        {
            sum=0;
            for(j=0; j<n;)
                if(a[j]!=i)
                {
                    sum++;
                    j+=k;
                }
                else
                    j++;
            if(sum<minn)
                minn=sum;
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include <bits/stdc++.h>
// #include <vector>
// #include <iostream>
// #include <string>

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin>>t;
    while(t--){
        int n, k;
        cin>>n>>k;
        vector<short> array(n);
        for (auto i = 0; i<n; i++)
            cin>>array[i];
        int minimal = 999999999;
        for (auto j = 1; j<=100; j++){
            int tmp = 0;
            for (auto i=0; i < n;){
                if (array[i]!=j){
                    tmp+=1;
                    i += k;
                } else
                {
                    i++;
                }

            }
            if (tmp < minimal)
                minimal = tmp;
        } cout<<minimal<<"\n";
    }
}


#include <bits/stdc++.h>
// #include <vector>
// #include <iostream>
// #include <string>

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin>>t;
    while(t--){
        int n, k;
        cin>>n>>k;
        vector<short> array(n);
        for (auto i = 0; i<n; i++)
            cin>>array[i];
        int minimal = 999999999;
        for (auto j = 0; j<100; j++){
            int tmp = 0;
            for (auto i=0; i<n;i++){
                if (array[i]!=j){
                    tmp+=1;
                    i+=k-1;
                }
            }
            if (tmp < minimal)
                minimal = tmp;
        } cout<<minimal<<"\n";
    }
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;

int n,k,mi,ans;
int c[maxn];

inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();}
    return x;
}
int main(){
    int t;
    t=read();
    while(t--){
        n=read();k=read();ans=1e8;
        for(int i=1;i<=n;i++)c[i]=read();
        for(int i=1;i<=100;i++){
        	mi=0;
        	for(int j=1;j<=n;j++){
            	if(c[j]!=i)mi++,j+=k-1;
        	}
        	ans=min(mi,ans);
		}
        printf("%d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100005;

int n,k,ma,ans,f;
int c[maxn],cnt[105];

inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();}
    return x;
}
int main(){
    int t;
    t=read();
    while(t--){
        n=read();k=read();ans=0;ma=0;f=0;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++){
            c[i]=read();
            cnt[c[i]]++;
            if(cnt[c[i]]>ma)f=c[i],ma=cnt[c[i]];
        }
        for(int i=1;i<=n;i++){
            if(c[i]!=f){
            	ans++;i+=k-1;
			}
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100005;

int n,k,ma,ans,f;
int c[maxn],cnt[105];

inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();}
    return x;
}
int main(){
    int t;
    t=read();
    while(t--){
        n=read();k=read();ans=0;
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++){
            c[i]=read();
            cnt[c[i]]++;
            if(cnt[c[i]]>ma)f=c[i],ma=cnt[c[i]];
        }
        for(int i=1;i<=n;i++){
            if(c[i]!=f){
            	ans++;i+=k-1;
			}
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0);
        int t;
        cin >> t;
        while(t--) {
                int n, k, ans=1000000000;
                cin >> n >> k;
                int T[n];
                rep(i, n) { cin >> T[i]; --T[i]; }
                rep(i, 100) {
                        int l=0, w=0;
                        while(l<n) {
                                while(l<n && T[l]==i) ++l;
                                if(l<n) {
                                        l+=k; ++w;
                                }
                        }
                        ans=min(ans, w);
                }
                cout << ans << '\n';
        }
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdb> vdb;
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define vv <vector<vector> >
#define mp make_pair
#define str(a, b) substr((a), (b))
#define rr return
#define r0 return 0
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
void adskiy_razgon(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0}, dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

void sp(ll a,double b) {
    cout << fixed << setprecision(a) << b;
}
template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vector<A>& x) {
    EACH(a, x) read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x) read(a);
}
string to_string(char c) {
    return string(1, c);
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vector<bool> v) {
    string res;
    FOR(sz(v)) res += char('0' + v[i]);
    return res;
}
template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S) res += char('0' + b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f) res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}
template<class A> void write(A x) {
    cout << to_string(x);
}
inline int bitCount(int number) {
    return __builtin_popcount(number);
}
inline int bitCount(ll number) {
    return __builtin_popcount(number);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
     write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t)) write(' ');
    print(t...);
}
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
void yes(bool ok) {
    print((ok ? "YES" : "Yes"));
}
void no(bool ok) {
    print((ok ? "NO" : "No"));
}
const int MOD = 1e9 + 7 ; // 888244353;
const int N = 2e6+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int M = 1005;
ll binpow (ll a, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 1) return ((binpow (a, n - 1) % MOD) * a) % MOD;
    else {
        ll b = (binpow (a, n / 2) % MOD);
        return (b * b) % MOD;
    }
}

void solve() {
    int n, m;
    read(n, m);
    vi a(n);
    for(int i = 0; i < n; ++i) {
        read(a[i]);
    }
    int ans = MOD;
    for(int i = 1; i <= 100; ++i) {
        int cnt = 0;
        vi b = a;
        for(int j = 0; j < n; ++j) {
            while(j < n && b[j] == i) j++;
            int k = m;
            if(j == n) break;
            cnt++;
            while(k-- && j < n) {
                b[j] = i;
                j++;
            }
            j--;
        }
        ans = min(ans, cnt);
    }
    print(ans);
}
int main(){
    adskiy_razgon();
    ll t = 1;
    read(t);
    FOR(t) {
        //write("Case ", i, ": ");
        solve();
    }
    r0;
}
/*

*/


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

int main(){
int t,n,k;
cin>>t;
while(t--){
	cin>>n>>k;
	vector<int>c(n);
	int color[101]={0};
	for(int i=0;i<n;i++){
	cin>>c[i];
	color[c[i]]=1;
	}
	int min=1e6;
	for(int i=1;i<=100;i++){
	if(color[i]==1){
		int acount=0;
		for(int j=0;j<n;j++){
		    if(c[j]!=i){
			    j+=k-1;
                acount++;
	         }
		}
		if(min>acount)min=acount;
	}
	}
	printf("%d\n",min);
}
return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int a[1000000];
int main(){
  int t;
  cin>>t;
  while(t--){
    int n,k,ans=10000000,tem=0,pd=0,z=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
      cin>>a[i];
    }
    for(int i=1;i<=100;i++){
      for(int j=1;j<=n;j++){
        if(a[j]!=i&&n-k>k){
          tem++;
          j+=k-1;
        }
        else if(a[j]!=i&&n-k<=k)
        {
          tem++;
          break;
        }
      }
      ans=min(ans,tem);
      tem=0;
    }
    cout<<ans<<endl;
  }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int a[1000000];
int main(){
  int t;
  cin>>t;
  while(t--){
    int n,k,ans=10000000,tem=0,pd=0,z=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
      cin>>a[i];
    }
    for(int i=1;i<=100;i++){
      for(int j=1;j<=n;j++){
        if(a[j]!=i){
          tem++;
          j+=k-1;
        }
      }
      ans=min(ans,tem);
      tem=0;
    }
    cout<<ans<<endl;
  }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define left 2*i+1
#define righ 2*i+2
#define mid (l+r)/2

using namespace std;
const ll maxn=2020;

int n,k;
vector<int>a;

int get(int c){
    int ret=0;
    for(int i=0;i<n;i++){
        if(a[i]!=c){
            ret++;
            i+=k-1;
        }
    }
    return ret;
}
void solve(){
    cin>>n>>k;
    a.resize(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=n;
    //cout<<get(1)<<' '<<get(2)<<endl;
    for(int i=1;i<=100;i++){
        ans=min(ans,get(i));
    }
    a.clear();
    cout<<ans<<endl;
}

int32_t main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
    return 0;
}


#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<map>
using namespace std;
int main(){
    long long t,n,k,ans;
    cin>>t;
    for(int j=0;j<t;j++){
        cin>>n>>k;
        vector<int>c(n);
        map<int,int>m;
        for(int i=0;i<n;i++){
            cin>>c[i];
            m[c[i]]++;
        }
        int maxx=0,im=0;
        for(auto i=m.begin();i!=m.end();i++){
            if(i->second>maxx){
                maxx=i->second;
                im=i->first;
            }
        }
        ans=(n-maxx)/k;
        int rm=ans,r=0;
        if((n-maxx)%k!=0){ans++;rm++;}
        for(int i=0;i<n-1;i++){
            if(c[i]!=im&&c[i+1]==im)r++;
        }
        if(c.back()!=im)r++;
        if(r>ans){
            ans=0;
            int i=0;
            while(i<=n-k){
                if(c[i]!=im){
                   for(int l=i;l<i+k;l++){
                        c[l]=im;
                    }
                    ans++;
                    i+=k;
                }else i++;

            }
        }
        cout<<ans<<endl;

    }

}


#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    long long t,n,k;
    cin>>t;
    for(int j=0;j<t;j++){
        cin>>n>>k;
        vector<int>c(n);
        map<int,int>m;
        for(int i=0;i<n;i++){
            cin>>c[i];
            m[c[i]]=0;
        }
        int ans=1000000000;
        for(auto i=m.begin();i!=m.end();i++){
            long long g=0, im=i->first, k1=k;
            vector<int>c1=c;
            while(g<n){
                if(c1[g]!=im){
                   for(int l=g;l<g+k1;l++){
                        c1[l]=im;
                    }
                    m[i->first]++;
                    g+=k1;

                }else g++;
                k1=min(k1,n-g);
            }
            //if(c1.back()!=im)m[i->first]++;

            if(m[i->first]<ans)ans=m[i->first];

        }
        cout<<ans<<endl;

    }

}


#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<map>
using namespace std;
int main(){
    long long t,n,k;
    cin>>t;
    for(int j=0;j<t;j++){
        cin>>n>>k;
        vector<int>c(n);
        map<int,int>m;
        for(int i=0;i<n;i++){
            cin>>c[i];
            m[c[i]]=0;
        }
        int ans=1000000000;
        for(auto i=m.begin();i!=m.end();i++){
            int g=0, im=i->first;
            vector<int>c1=c;
            while(g<=n-k){
                if(c1[g]!=im){
                   for(int l=g;l<g+k;l++){
                        c1[l]=im;
                    }
                    m[i->first]++;
                    g+=k;
                }else g++;

            }
            if(c1.back()!=im)m[i->first]++;

            if(m[i->first]<ans)ans=m[i->first];

        }
        cout<<ans<<endl;

    }

}


#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<map>
using namespace std;
int main(){
    long long t,n,k;
    cin>>t;
    for(int j=0;j<t;j++){
        cin>>n>>k;
        vector<int>c(n);
        map<int,int>m;
        for(int i=0;i<n;i++){
            cin>>c[i];
            m[c[i]]=1;
        }
        int ans;
        for(auto i=m.begin();i!=m.end();i++){
            int g=0, im=i->first;
            vector<int>c1=c;
            ans=1000000000;
            while(g<=n-k){
                if(c1[g]!=im){
                   for(int l=g;l<g+k;l++){
                        c1[l]=im;
                    }
                    m[i->first]++;
                    g+=k;
                }else g++;

            }
            if(c1.back()!=im)m[i->first]++;\
            if(m[i->first]<ans)ans=m[i->first]-1;

        }
        cout<<ans<<endl;

    }

}


#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<map>
using namespace std;
int main(){
    long long t,n,k,ans;
    cin>>t;
    for(int j=0;j<t;j++){
        cin>>n>>k;
        vector<int>c(n);
        map<int,int>m;
        for(int i=0;i<n;i++){
            cin>>c[i];
            m[c[i]]++;
        }
        int maxx=0,im=0;
        for(auto i=m.begin();i!=m.end();i++){
            if(i->second>maxx){
                maxx=i->second;
                im=i->first;
            }
        }

            ans=0;
            int i=0;
            while(i<=n-k){
                if(c[i]!=im){
                   for(int l=i;l<i+k;l++){
                        c[l]=im;
                    }
                    ans++;
                    i+=k;
                }else i++;

            }
            if(c.back()!=im)ans++;
        cout<<ans<<endl;

    }

}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>
#include<memory.h>
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=998244353;
//const long long LMOD=154590409516822759;
const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define Pil pair<int,long long>
#define Pli pair<long long,int>
#define Cb make_pair
#define ll long long
#define Ull unsigned long long
#define Sf scanf
#define Pf printf
#define Pb push_back
#define Psh push
#define Stc stack
#define Vct vector
#define Ret return
#define Re0 return 0
#define Sz size
#define Is insert
#define Que queue
#define Emp empty
#define Fro front
#define Rv reverse
#define Er erase
#define Bg begin
#define Srt sort
#define Pq priority_queue
#define Ins insert
#define Ite iterator
#define Cou count
#define Cot continue
#define Swp swap
#define Bre break
#define Beg begin
#define Upb upper_bound
#define Lwb lower_bound
int n,m;
int a[100001];
int MIAN()
{
	Sf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		Sf("%d",&a[i]);
	}
	int g=0,s=0;
	int mn=100000;
	for(int i=1;i<=100;i++)
	{
		g=0;
		for(int j=1;j<=n;j++)
		{
			if(s==0&&a[j]!=i)
			{
				s=m;
				g++;
			}
			if(s>0)s--;
		}
		//cout<<i<<":"<<g<<endl;
		mn=min(mn,g);
	}
	Pf("%d\n",mn);
	return 0;
}
int main()
{
	int t;
	Sf("%d",&t);
	while(t--)MIAN();
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>
#include<memory.h>
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=998244353;
//const long long LMOD=154590409516822759;
const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define Pil pair<int,long long>
#define Pli pair<long long,int>
#define Cb make_pair
#define ll long long
#define Ull unsigned long long
#define Sf scanf
#define Pf printf
#define Pb push_back
#define Psh push
#define Stc stack
#define Vct vector
#define Ret return
#define Re0 return 0
#define Sz size
#define Is insert
#define Que queue
#define Emp empty
#define Fro front
#define Rv reverse
#define Er erase
#define Bg begin
#define Srt sort
#define Pq priority_queue
#define Ins insert
#define Ite iterator
#define Cou count
#define Cot continue
#define Swp swap
#define Bre break
#define Beg begin
#define Upb upper_bound
#define Lwb lower_bound
int n,m;
int a[100001];
int MIAN()
{
	Sf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		Sf("%d",&a[i]);
	}
	int g=0,s=0;
	int mn=100000;
	for(int i=1;i<=100;i++)
	{
		g=0;
		s=0;
		for(int j=1;j<=n;j++)
		{
			if(s==0&&a[j]!=i)
			{
				s=m;
				g++;
			}
			if(s>0)s--;
		}
		//if(i<=10)cout<<i<<":"<<g<<endl;
		mn=min(mn,g);
	}
	Pf("%d\n",mn);
	return 0;
}
int main()
{
	int t;
	Sf("%d",&t);
	while(t--)MIAN();
	return 0;
}


#include<bits/stdc++.h>
#define len(s) (int)s.size()
using namespace std;
using ll = long long;
using ld = long double;

const int inf = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;

    for(int q = 0; q < t; q++){
        ll n, k;
        cin >> n >> k;

        vector<int>house(n);
        vector<int>color(102, 0);

        for(int i = 0; i < n; i++) {
            cin >> house[i];
            color[house[i]]++;
        }

        int answer = inf;
        for(int col = 1; col <= 100; col++){
            if(color[col] == 0) continue;
            int col_res = 0;
            int l = 0;
            for(int i = 0; i < n; i++){
                if(house[i] != col) l++;
                else {
                    col_res += (l + k - 1) / k;
                    l = 0;
                }
            }
            if(l > 0) col_res += (l + k - 1) / k;
            answer = min(col_res, answer);
            //cout << "test " << col << ' ' << col_res << '\n';
        }
        cout << answer << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>
#define len(s) (int)s.size()
using namespace std;
using ll = long long;
using ld = long double;

const int inf = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;

    for(int q = 0; q < t; q++){
        ll n, k;
        cin >> n >> k;

        vector<int>house(n);
        vector<int>color(102, 0);

        for(int i = 0; i < n; i++) {
            cin >> house[i];
            color[house[i]]++;
        }

        int answer = inf;
        for(int col = 1; col <= 100; col++){

            if(color[col] == 0) continue;
            int col_res = 0;

            int l = 0; // длина покрашенных
            for(int i = 0; i < n; i++){
                if(house[i] != col) l++; //красим
                else {
                    if(l > 0) l++; // все равно докрасим участок
                }
                if(l == k){
                    col_res++;
                    l = 0;
                }
            }
            if(l > 0) col_res++;
            answer = min(col_res, answer);
            //cout << "test " << col << ' ' << col_res << '\n';
        }
        cout << answer << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn = 1e5+5;
int col[maxn];

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        for(int i = 0;i<n;i++)
            cin>>col[i];
        int ans = maxn;
        for(int i = 1;i<=100;i++)
        {
            int tmp = 0;
            for(int j = 0;j<n;j++)
            {
                if(col[j] == i)
                    continue;
                tmp ++;
                j+=k-1;
            }
            ans  = min(ans,tmp);
        }
        cout<<ans<<endl;

    }

    return 0;
}


#include <bits\stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    int a[100007], vis[107];

    while (t--) {
        int n, k;
        cin >> n >> k;
        memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
            vis[a[i]]++;
        }
        int ans = n / k + 1;
        for (int i = 1; i <= 100; ++i) {
            if (vis[i] > 0) {
                int cnt = 0;
                for (int j = 1; j <= n; ++j) {
                    if (a[j] != i) {
                        cnt++;
                        j += k - 1;
                    }
                }
                ans = min(ans, cnt);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits\stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    int a[100007], vis[107];

    while (t--) {
        int n, k;
        cin >> n >> k;
        memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
            vis[a[i]]++;
        }
        int ans = n / k + 1;
        for (int i = 1; i <= 100; ++i) {
            if (vis[i] > 0) {
                int cnt = 0;
                for (int j = 1; j <= n; ++j) {
                    if (a[j] != i) {
                        cnt++;
                        j += k;
                    }
                }
                ans = min(ans, cnt);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits\stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    int a[100007], vis[107];

    while (t--) {
        int n, k;
        cin >> n >> k;
        memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
            vis[a[i]]++;
        }
        int ans = n / k;
        for (int i = 1; i <= 100; ++i) {
            if (vis[i] > 0) {
                int cnt = 0;
                for (int j = 1; j <= n; ++j) {
                    if (a[j] != i) {
                        cnt++;
                        j += k - 1;
                    }
                }
                ans = min(ans, cnt);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#define endl '\n'
#define fixstd() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define precision(n) cout.setf(ios::fixed); cout.precision(n)
#define all(arr) arr.begin(), arr.end()
#define sz(arr) int(arr.size())
#define print(arr) {for (auto el: arr) cout << el << ' '; cout << endl;}
#define pprint(A) for (auto &x: A) print(x)
#define read(arr) for (auto &el: arr) cin >> el
#define mu(arr) {sort(all(arr)); arr.resize(unique(all(arr)) - arr.begin());}
#define multitest() int _; cin >> _; for (; _; --_)
#define yesno(fl) (fl ? "YES" : "NO")
#define out(n) {cout << n << endl; exit(0);}
#define write(n) cout << n << endl
#define debug(s, n) cout << s << ": " << n << endl
#define cline() cout << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
typedef long long lint;
typedef long double ld;
typedef string str;
#define int lint
typedef pair<int, int> col;
typedef pair<lint, lint> coll;
typedef pair<ld, ld> cold;
typedef pair<str, str> cols;

const int INF = 1e9;
const int N = 101;
int n, k;
vector<int> arr;
vector<bool> used;

void init() {
	arr.resize(n);
	used.assign(N, false);
}

int color(int c) {
	int res = 0;
	for (int i = 0; i < n;) {
		if (arr[i] == c) ++i;
		else i += k, ++res;
	}
	return res;
}

int solve() {
	for (int c: arr)
		used[c] = true;
	//print(used);
	int ans = INF;
	for (int c = 0; c < N; ++c)
		if (used[c]) ans = min(ans, color(c));
	return ans;
}

signed main() {
	fixstd();
	multitest() {
		cin >> n >> k, init();
		read(arr);
		write(solve());
	}
}


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

void solve() {
	int n, k;
	cin >> n >> k;

	vector<int> v(n);
	for(int i = 0; i < n; i++) cin >> v[i];

	int MIN = 1e9+7;
	for(int cl = 1; cl <= 100; cl++) {
		int cnt = 0;
		int st = 0;

		while(st < n) {
			while(st < n && v[st] == cl) st++;
			if(st == n) break;
			st = st + k;
			cnt++;
		}

		MIN = min(MIN, cnt);
	}

	cout << MIN << endl;
}

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


#include<bits/stdc++.h>
using namespace std;
int main(){
	int q;
	cin>>q;
	for(int p=0;p<q;p++){

		int n,k;
		cin>>n>>k;
		vector<int> c(n);
		vector<bool> unicol(101, false);

		for(int i=0;i<n;i++){
			cin>>c[i];
			unicol[c[i]]=true;
		}
		int mis=100000000;
		for(int i=0; i<unicol.size();i++){

			if(unicol[i]){
				int nowsum=0;
				for(int j=0;j<n;j++){
					if(c[j]!=i){
						nowsum++;
						if(j+k-1<n) j+=k-1;
						else break;
					}
				}
				mis=min(mis,nowsum);

			}
		}
		cout<<mis<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
namespace IO{
	#define iL (1<<20)
	char ibuf[iL],*iS=ibuf+iL,*iT=ibuf+iL;
	#define gc() ((iS==iT)?(iT=(iS=ibuf)+fread(ibuf,1,iL,stdin),(iS==iT)?EOF:*iS++):*iS++)
	template<class T>inline void read(T &x){
		register char c;
		for(c=gc();!isdigit(c);c=gc());
		for(x=0;isdigit(c);x=(x<<1)+(x<<3)+(c^48),c=gc());
		return ;
	}
	char Out[iL],*iter=Out;
	#define flush() fwrite(Out,1,iter-Out,stdout),iter=Out
	template<class T>inline void write(register T x){
		register T c[35],l;
		for(l=0;!l || x;c[l]=x%10,++l,x/=10);
		for(;l;--l,*iter++=c[l]+'0');
		flush();
		return ;
	}
	template<class T>inline void write(register T x,register char LC){
		write(x),*iter++=LC;
		return ;
	}
}
using namespace IO;
int T,n,m,ans,a[200005],b[200005];
int main(){
	read(T);
	for(register int _=0;_<T;++_){
		read(n),read(m),ans=INT_MAX;
		for(register int i=1;i<=n;++i){
			read(a[i]);
		}
		for(register int i=1;i<=n;++i){
			b[i]=a[i];
		}
		for(register int j=1;j<=100;++j){
			int sum=0;
			for(register int i=1;i<=n;++i){
				a[i]=b[i];
			}
			for(register int i=1;i<=n;++i){
				if(a[i]^j){
					++sum;
					int k=i;
					while(i-k+1<m){
						a[i]=j,++i;
					}
				}
			}
			ans=min(ans,sum);
		}
		write(ans,'\n');
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int inf=1e9+7;
int a[100005];
int vis[109];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int n,k,maxn=0;
		memset(vis,0,sizeof(vis));
		scanf("%d %d",&n,&k);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			maxn=max(maxn,a[i]);
			vis[a[i]]=1;
		}
		int ans=0,minn=inf;
		for(int i=1;i<=maxn;i++){
			if(vis[i]){
				ans=0;
				for(int j=1;j<=n;j++){
					if(a[j]!=i){
						ans++;
						j=j+k-1;
					}
				}
				minn=min(ans,minn);
			}
		}
		printf("%d\n",minn);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int inf=1e9+7;
int a[100005];
int vis[109];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int n,k,maxn=0;
		memset(vis,0,sizeof(vis));
		scanf("%d %d",&n,&k);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			maxn=max(maxn,a[i]);
			vis[a[i]]=1;
		}
		int ans=0,minn=inf;
		for(int i=1;i<=maxn;i++){
			if(vis[i]){
				ans=0;
				for(int j=1;j<=n;j++){
					if(a[j]!=i){
						ans++;
						j=j+k-1;
					}
				}
			}
			minn=min(ans,minn);
		}
		printf("%d\n",minn);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int inf=1e9+7;
int a[100005];
int vis[109];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int n,k,maxn=0;
		memset(vis,0,sizeof(vis));
		scanf("%d %d",&n,&k);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			maxn=max(maxn,a[i]);
			vis[a[i]]=1;
		}
		int ans=0,minn=inf;
		for(int i=1;i<=maxn;i++){
			if(vis[i]){
				ans=0;
				for(int j=1;j<=n;j++){
					if(a[j]!=i){
						ans++;
						j=j+k-1;
					}
				}
			}
			minn=min(ans,minn);
		}
		printf("%d\n",minn);
	}
	return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define range(i, n) for (int i=0; (i) < n; ++(i))
#define rrange(i, n) for (int i=n-1; i>-1; --i)
#define fi first
#define se second
#define mp make_pair
#define sz(x) ((int)(x).size())
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
//#define int long long
typedef long long ll;
typedef long double ld;

using namespace std;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
const ll inf = 2e9;
const int maxn = 2e5 + 1;
const bool debug = 1;
const int64_t INF = 1e17;
const int module =998244353;

void solve() {
  int n,k,answer=inf;
  cin>>n>>k;
  vi c(n);
  range(i,n)
    cin>>c[i];

  for (int i = 1; i <=100 ; ++i){
      int l=0,x=0;
      while (l<n){
          if (c[l]==i){
              l++;
          }
          else{
              x++;
              l+=k;
          }
      }
      answer=min(answer,x);
  }
  cout<<answer;
}

int32_t main() {
    if (!debug) {
        cin.tie(0);
        cout.tie(0);
        ios::sync_with_stdio(0);
    }
    ll tests = 1;
    cin >> tests;
    range(_, tests) {
        solve();
        cout << "\n";
    }
    return 0;
}
/*
2
4
2

*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int long long
const int maxn = 1e6+10;
inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

int n,m,q;
int f[maxn];
map<int,int>mp;
map<int,int>res;
signed main()
{
    int t =read();
    while(t--){
        int n =read(),k =read();
        mp.clear();
        res.clear();
        int mmin = n;

        for(int i =1;i<=n;i++){
            int u ;
            cin>>u;
            if(i-mp[u]-1>0)res[u] += (i-mp[u]-2)/k+1;
//            cout<<i<<" "<<res[u]<<endl;
            mp[u] = i;
        }
        for(auto x:res){
            int d = x.second;
            if(n-mp[x.first]>0) d += (n-mp[x.first]-1)/k+1;
            mmin = min(mmin,d);
        }
        cout<<mmin<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int long long
const int maxn = 1e6+10;
inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

int n,m,q;
int dp[100010][101];
map<int,int>mp;
map<int,int>res;
signed main()
{
    int t =read();
    while(t--){
        int n =read(),k =read();
        mp.clear();
        res.clear();
        int mmin = (n-1)/k+1;
        for(int i = 0;i<=100;i++){
            dp[0][i] = 0;
        }
        for(int i =1;i<=n;i++){
            int u ;
            cin>>u;
            int lst = max(0LL,i-k);
            for(int j = 1;j<=100;j++){
                dp[i][j] = dp[lst][j] +1;
            }
            dp[i][u] = min(dp[i][u],dp[i-1][u]);
//            if(i-mp[u]-1>0)res[u] += (i-mp[u]-2)/k+1;
//            cout<<i<<" "<<res[u]<<endl;
//            mp[u] = i;
        }
        for(int i = 1;i<=100;i++){
            mmin = min(mmin,dp[n][i]);
        }
//        for(auto x:res){
//            int d = x.second;
//            if(n-mp[x.first]>0) d += (n-mp[x.first]-1)/k+1;
//            mmin = min(mmin,d);
//        }
        cout<<mmin<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int t, n, k;
int c[100010];
int main()
{
	scanf("%d", &t);
	while(t --)
	{
		scanf("%d%d", &n, &k);
		for (int i = 1; i <= n; ++ i)
		{
			scanf("%d", &c[i]);
		}
		int ans = 1e9;
		for (int col = 1; col <= 100; ++ col)
		{
			int now = 0;
			for (int i = 1; i <= n; ++ i)
			{
				if(c[i] != col)
				{
					++ now;
					i += k - 1;
				}
			}
			ans = min(ans, now);
		}
		printf("%d\n", ans);
	}
}


#include <iostream>
#include <algorithm>

using namespace std;
int main()
{
	int t;
	cin >> t;
	for (int j=0; j<t; j++)
	{
		int n, k, h=0;
		cin >> n >> k;
		int m[n];
		for (int i=0; i<n; i++)
			cin >> m[i];
		int c1[100+1];
		for (int i=1; i<101; i++)
		{
			h=0;
			for (int l=0; l<n; l++)
			{
				if (m[l] != i)
				{
					h++;
					l+=k-1;
				}
			}c1[i]=h;
		}
		sort(c1+1, c1+101);
		cout << c1[1] << endl;
	}

}


#include <iostream>
#include <cmath>

using namespace std;
int main()
{
	int t;
	cin >> t;
	int n, m, i, j, s =0 ;
	while (s < t)
	{
		cin >> n >> m >> i >> j;
		int a1 = i+j-2, a2 = i+m-j-1, a3 = n-i+j-1, a4 = n-i+m-j;
		int m = max(max(a1, a2), max(a3, a4));
		cout << m << endl;
		s++;
	}
}


#include<iostream>
using namespace std;

int t;
int n,m;
int a[100005];
int ans=0,rans=0x7fffffff;

int main(){
	int i,j,k;
	cin>>t;
	for(i=0;i<t;i++){
		ans=0;
		rans=0x7fffffff;
		cin>>n>>m;
		for(j=0;j<n;j++)
			cin>>a[j];
		int tot=0;
		for(j=0;j<100;j++){
			ans=0;
			for(k=0;k<n;k++){
				if(a[k]!=j){
					ans++;
					k+=m-1;
				}
			}
			rans=min(rans,ans);
		}
		cout<<rans<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

int t;
int n,m;
int a[100005];
int ans=0,rans=0x7fffffff;

int main(){
	int i,j,k;
	cin>>t;
	for(i=0;i<t;i++){
		ans=0;
		rans=0x7fffffff;
		cin>>n>>m;
		for(j=0;j<n;j++)
			cin>>a[j];
		int tot=0;
		for(j=0;j<100;j++){
			ans=tot=0;
			for(k=0;k<n;k++){
				//cout<<j<<" "<<k<<" "<<tot<<" "<<ans<<"\t\t";
				if(a[k]!=j)
					tot++;
				else{
					ans+=tot/m+(bool)(tot%m);
					tot=0;
				}
			}
			ans+=tot/m+(bool)(tot%m);
			rans=min(rans,ans);
			//cout<<endl;
		}
		cout<<rans<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

int t;
int n,m;
int a[100005];
int ans=0,rans=0x7fffffff;

int main(){
	int i,j,k;
	cin>>t;
	for(i=0;i<t;i++){
		ans=0;
		rans=0x7fffffff;
		cin>>n>>m;
		for(j=0;j<n;j++)
			cin>>a[j];
		int tot=0;
		for(j=0;j<=100;j++){
			ans=0;
			for(k=0;k<n;k++){
				if(a[k]!=j){
					ans++;
					k+=m-1;
				}
			}
			rans=min(rans,ans);
		}
		cout<<rans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxc = 101;
const ll maxn = 1e5 + 1;
ll a[maxn];
int main() {
    ll T;
    cin >> T;
    for (ll t = 0; t < T; t++) {
        ll n, k;
        cin >> n >> k;
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
        }
        ll ans = 1e9 + 1;
        for (ll c = 1; c < maxc; c++) {
            vector<ll> v;
            for (ll i = 0; i < n; i++) {
                if (a[i] != c)
                    v.push_back(i);
            }
            if (v.size() == 0) {
                ans = 0;
                break;
            }
            ll i = v[0];
            ll ansT = 0;
            while (i < n) {
                //cout << i << "--";
                ll p = lower_bound(v.begin(), v.end(), i + k) - v.begin();
                ansT++;
                if (p >= v.size()) {
                    //cout << n << " ";
                    i = n;
                }
                else {
                    //cout << v[p] << " ";
                    i = v[p];
                }
            }
            //cerr << c << " " << ansT << "\n";
            ans = min(ans, ansT);
        }
        cout << ans << "\n";
    }
}


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

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(vector<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcTU> str ts(pair<T,U> p);
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;

	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.f)+", "+ts(p.s)+")";
	#else
		return ts(p.f)+" "+ts(p.s);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); }
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
	cerr << ts(t); if (sizeof...(u)) cerr << ", ";
	DBG(u...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
	#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
	#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
		 << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
	#define dbg(...) 0
	#define chk(...) 0
#endif

// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}
void tc() {
	int n, k, tmp;
	cin >> n >> k;
	vector<int> colors;
	F0R(i, n){
		cin >> tmp;
		colors.push_back(tmp);
	}
	int min_day = 100000;
	int day_spent = 0;
	int t;
	FOR(ci, 1, 101){
		t = 0;
		day_spent = 0;
		while(t < n){
			if(colors[t] == ci)
				t++;
			else {
				day_spent++;
				t+=k;
			}
		}
		min_day = min(min_day, day_spent);
	}
	cout << min_day << endl;
}

int main() {
	int t;
	cin >> t;
	F0R(i, t) tc();
	// you should actually read the stuff at the bottom
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


#include<bits/stdc++.h>
using namespace std;
const int maxn=100+2;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int arr[n+1];
        for(int i=1;i<=n;i++)
        cin>>arr[i];
        vector<int>v[maxn+2];
        for(int i=1;i<=n;i++)
        {
            v[arr[i]].push_back(i);
        }
        int min1=INT_MAX;
        for(int i=1;i<maxn;i++)
        {
           int count=0;
           int val=1;
           for(int j=0;j<v[i].size();j++)
           {
               if(v[i][j]==val)
               val++;
               else if(v[i][j]>val)
               {
                   int a=(v[i][j]-val)/k;
                   val=a*k+val;
                   count=count+a;
                   if(val==v[i][j])
                   val++;
                   else
                   {
                   val=val+k;
                   count++;
                   }
               }

           }
           if(val<=n)
           {
              count=count+(n-val+1)/k;
              if((n-val+1)%k!=0)
              count++;
           }
           min1=min(count,min1);
        }
        cout<<min1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[300000];
int b[300000];
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n,k;
		scanf("%d %d",&n,&k);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			b[a[i]]++;
		}
		int ans=INT_MAX;
		for(int i=1;i<=100;i++){
			int count=0;
			if(b[i]!=0){
				for(int j=1;j<=n;j++){
					if(a[j]!=i){
						j+=k-1;
						count++;
					}
				}
				ans=min(ans,count);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// using namespace std::chrono;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define mod 1000000007
#define DEB(x) cout << #x << "=" << x << endl
#define DEB2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
/* If we have to paint all numbers from 1 to n, except those in
 * the vector V, how many do we need ? */
int getSeg(const vector<int> &V, const int n, const int k) {
  int cnt = 0, st = 0, m;
  for (auto v : V) { // has at least one element
    if (v == st + 1)
      st++;
    else if (v > st) {
      m = (v - st - 2) / k + 1;
      cnt += m;
      st += m * k;
      if (v == st + 1)
        st++;
    }
  }
  if (st < n) {
    m = (n - st - 1) / k + 1;
    cnt += m;
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T = 1, n, k, a, cnt;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    map<int, vector<int>> F;
    REP(i, 1, n) {
      cin >> a;
      F[a].PB(i);
    }
    cnt = n;
    for (auto f : F) { // check the vecctor f.second and find the number
      cnt = min(cnt, getSeg(f.second, n, k));
    }
    cout << cnt << endl;
    // cout << F.size() << endl;
  }

  return 0;
}
// auto start = high_resolution_clock::now();
// auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);
// cout << duration.count() / 1000.0 << endl;


#include <bits/stdc++.h>
#define reg register
#define rep(i,a,b) for(reg int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(reg int i=a,i##end=b;i>=i##end;i--)
inline int read() {
	int x=0;char c=getchar();
	while(c<48||c>57){c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}
using namespace std;
const int M=1e5+5;
int A[M];
int main() {
	int T=read();
	while(T--){
		int n=read(),m=read();
		rep(i,1,n)A[i]=read();
		int ans=1e9;
		rep(i,1,100){
			int p=1,cnt=0;
			while(p<=n){
				while(p<=n&&A[p]==i)p++;
				if(p<=n)p+=m,cnt++;
			}
			ans=min(ans,cnt);
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int Read(){
  	int s = 0 , w = 1;
	char ch = getchar();
	while(ch > '9' || ch < '0'){
		if(ch == '-') w = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		s = (s << 1) + (s << 3) + ch - '0';
		ch = getchar();
	}
	return s * w;
}
const int MAXN = 1e5 + 50;
int T;
int n,k,a[MAXN],num[MAXN];
int main(){
	T = Read();
	while(T --){
		memset(num,0,sizeof(num));
		int ans = 19260817;
		n = Read() , k = Read();
		for(int i = 1 ; i <= n ; i ++) a[i] = Read();
		for(int i = 1 ; i <= n ; i ++) num[a[i]] = true;
		for(int c = 1 ; c <= 100 ; c ++){
			if(num[c]){
				int res = 0;
				for(int i = 1 ; i <= n ; i ++){
					if(a[i] != c){
						res ++;
						i += k - 1;
					}
				}
				ans = min(res,ans);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t;
int n, k;
int a[100005];
int main()
{
	cin >> t;
	while (t--)
	{
		map<int, int> mp;
		int ans = 99999999;
		cin >> n >> k;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			mp[a[i]] = 1;
		}
		for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
		{
			int cnt = 0;
			for (int i = 1; i <= n;)
			{
				if (a[i] != it->first)
					i += k, cnt += 1;
				else
					i++;
			}
			ans = min(cnt, ans);
		}
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int t, n, k, ai;
  scanf("%d", &t);

  while(t--) {
    scanf("%d %d", &n, &k);
    int maxVal = -1;
    int cCounter = -1;
    vector<int> arr, counter(n+1);

    for (int i = 0; i < n; i++) {
      scanf("%d", &ai);
      arr.push_back(ai);
      counter[ai]++;
      if (counter[ai] > cCounter) {
        maxVal = ai;
        cCounter = counter[ai];
      }
    }

    // cout << "maxVal" << '\n';
    // cout << maxVal << '\n';

    int ans = 0;
    for (int i = 0; i < n; i=i) {
      if (arr[i] != maxVal) {
        ans++;
        i+= k;
      } else {
        i++;
      }
    }
    //
    // cout << "ans" << '\n';
    cout << ans << '\n';
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int t, n, k, ai;
  scanf("%d", &t);

  while(t--) {
    scanf("%d %d", &n, &k);
    int maxVal = -1;
    int cCounter = -1;
    vector<int> arr;
    set<int> mySet;

    for (int i = 0; i < n; i++) {
      scanf("%d", &ai);
      arr.push_back(ai);
      mySet.insert(ai);
    }

    int ans = n;
    for (int val: mySet) {
      int aux = 0;
      for (int i = 0; i < n; i=i) {
        if (arr[i] != val) {
          aux++;
          i+= k;
        } else {
          i++;
        }
      }

      ans = min(ans, aux);
    }

    cout << ans << '\n';
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 110;
int T,n,a[100010],k;
int b[100010],tot = 0,maxans,cnt =0;
int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

int main(){
	cin>>T;
	while(T--){
		tot = 0;
		maxans = 0;
		n = read(),k = read();
		for(int i=1;i<=n;i++){
			a[i] = read();
		}
		int Ans = n*10;
		for(int i=1;i<=100;i++){
			int ans = 0;
			for(int j=1;j<=n;j++){
				if(a[j]!=i){
					ans++,j+=k-1;
				}
			}
			Ans = min(ans,Ans);
		}
		cout<<Ans<<endl;
	}
}


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

int main() {
    int t;
    cin >> t;
    while(t--) {
    	int n, k;
    	cin >> n >> k;
    	vector<int> v(n);
    	map<int,int> m;
    	for(auto &i : v) {
    		cin >> i; m[i]++;
    	}
    	int ans = 1000000000;
    	for(auto i : m) {
    		int cnt = 0;
    		for(int j = 0; j < n; j++) {
    			if(v[j] != i.first) {
    			    j += k - 1; cnt++;
    			}
    		}
    		ans = min(cnt, ans);
    	}
    	cout << ans << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ll t, n, k;
    cin >> t;
    while (t--) {
        cin >> n >> k;
        vector <ll> c(n);
        for (ll i = 0; i < n; ++i) {
            cin >> c[i];
        }
        ll colour[n];
        for (ll i = 0; i < n; ++i) {
            colour[i] = 0;
        }
        ll maxi = INT_MIN, max_i = 0;
        for (ll i = 0; i < n; ++i) {
            colour[c[i]]++;
            if (colour[c[i]] > maxi) {
                maxi = colour[c[i]];
                max_i = c[i];
            }
        }
        sort(c.begin(), c.end());
        ll cnt = 0;
        for (ll i = 0; i < n - k; i += k) {
            if (c[i] < max_i) {
                cnt++;
            }
        }
        cout << cnt << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ll t, n, k;
    cin >> t;
    while (t--) {
        cin >> n >> k;
        ll c[n];
        for (ll i = 0; i < n; ++i) {
            cin >> c[i];
        }
        ll cnt, ans = INT_MAX;
        for (ll i = 1; i <= 100; ++i) {
            cnt = 0;
            for (ll j = 0; j < n; ++j) {
                if (c[j] != i) {
                    cnt++;
                    j += k - 1;
                }
            }
            ans = min(ans, cnt);
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <iostream>
using namespace std;
int main() {
	int n, a[1000];
	cin >> n;
	if (n < 2 || n>100)
		cout << 0;
	else {
		for (int i = 0; i < n; i++)
			cin >> a[i];}
	int r = a[0], l=0;
	int m = a[0], p=0;
	for (int i = 0; i < n; i++) {
		if (r <= a[i]) {
			r = a[i];
			l = i;
		}}
	for (int i = 0; i < n; i++) {
		if (m > a[i]) {
			m = a[i];
			p = i;
		}}
		if (p < l)
		{
			int x = n - p-1;
			int z =  l-1;
			cout << (x + z) - 1 << endl;
		}
		else
		{
			int x = n - p-1;
			int z = l;
			cout << (x + z) << endl;
		}}


#include <iostream>
using namespace std;
int main() {
	int n, a[1000];
	cin >> n;
	if (n < 2 || n>100)
		cout << 0;
	else {
		for (int i = 0; i < n; i++)
			cin >> a[i];}
	int r = a[0], min=0;
	int m = a[0], max=0;
	for (int i = 1; i < n; i++) {
		if (r <= a[i]) {
			r = a[i];
			max = i;
		}}
	for (int i = 1; i < n; i++) {
		if (m >= a[i]) {
			m = a[i];
			min = i;
		}}
		if (max > min)
		{
			int x = n - min-1;
			int z =  max;
			cout << (x + z) - 1 << endl;
		}
		else
		{
			int x = n - min-1;
			int z = max;
			cout << (x + z) << endl;
		}}


#include <iostream>
using namespace std;
int main() {
	int n, a[1000];
	cin >> n;
	if (n < 2 || n>100)
		cout << 0;
	else {
		for (int i = 0; i < n; i++)
			cin >> a[i];}
	int r = a[0], mn=0;
	int m = a[0], mx=0;
	for (int i = 1; i < n; i++) {
		if (r < a[i]) {
			r = a[i];
			mx = i;
		}}
	for (int i = 1; i < n; i++) {
		if (m > a[i]) {
			m = a[i];
			mn = i;
		}}
		if (mx > mn)
		{
			int x = n - mn-1;
			int z =  mx;
			cout << (x + z) - 1 << endl;
		}
		else
		{
			int x = n - mn-1;
			int z = mx;
			cout << (x + z) << endl;
		}}


#include <iostream>
using namespace std;
int main() {
	int n, a[1000];
	cin >> n;
	if (n < 2 || n>100)
		cout << 0;
	else {
		for (int i = 0; i < n; i++)
			cin >> a[i];}
	int r = a[0], mn=0;
	int m = a[0], mx=0;
	for (int i = 1; i < n; i++) {
		if (r < a[i]) {
			r = a[i];
			mx = i;
		}}
	for (int i = 1; i < n; i++) {
		if (m >= a[i]) {
			m = a[i];
			mn = i;
		}}
		if (mx > mn)
		{
			int x = n - mn-1;
			int z =  mx;
			cout << (x + z) - 1 << endl;
		}
		else
		{
			int x = n - mn-1;
			int z = mx;
			cout << (x + z) << endl;
		}}


#include <iostream>
using namespace std;
int main() {
	int n, a[1000], count1 = 0, count2 = 0;
	cin >> n;
	if (n <= 0)
		cout << 0;
	else {
		for (int i = 0; i < n; i++)
			cin >> a[i];
	}
	int r = a[0], l=0;
	int m = a[0], p=0;
	for (int i = 1; i < n; i++) {
		if (r <= a[i]) {
			r = a[i];
			l = i;

		}
		else
			continue;
	}
	count1 = l;
		for (int i = 1; i < n; i++) {
			if (m > a[i]) {
				m = a[i];
				p = i;

			}
			else
				continue;
		}
		count2 = p;
		if (count2 < count1)
		{

			int x = n - count2;
			int z = count1;
			cout << (x + z) - 1 << endl;

		}
		else
		{
			int x = n - count2;
			int z = count1;
			cout << (x + z) << endl;
		}
	}


#include <iostream>
using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	if (minPos < maxPos) {
		cout << n - minPos + maxPos - 2;
	}
	else {
		cout << n - minPos + maxPos - 1;
	}

	return 0;
}


#include <iostream>

using namespace std;

int SelectionSort(int *a, int n) {
	int kq = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] < a[j]) {
				kq++;
				int temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	return kq;
}

void main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << SelectionSort(a, n);
}


#include <iostream>
using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	cout << minPos << maxPos;
	if (minPos < maxPos) {
		cout << n - minPos + maxPos - 2;
	}
	else {
		cout << n - minPos + maxPos - 1;
	}

	return 0;
}


#include <iostream>

using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i > -1; i++) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << n - FindMin(a, n) + FindMax(a, n) - 2;
	return 0;
}


#include <iostream>

using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << n - FindMin(a, n) + FindMax(a, n) - 2;
	return 0;
}


#include <iostream>

using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	if (minPos < maxPos) {
		cout << n - FindMin(a, n) + FindMax(a, n) - 2;
	}
	else {
		cout << n - FindMin(a, n) + FindMax(a, n) - 1;
	}

	return 0;
}


#include <iostream>

using namespace std;

int SelectionSort(int *a, int n) {
	int kq = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] < a[j]) {
				kq++;
				int temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	return kq;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << SelectionSort(a, n);
	return 0;
}


#include <iostream>
using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = (i == 1) ? i - 1 : i;

		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = (i == n - 2) ? i + 1 : i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	//cout << minPos << " " << maxPos << endl;
	if (minPos < maxPos) {
		cout << n - minPos + maxPos - 2;
	}
	else {
		cout << n - minPos + maxPos - 1;
	}
	//system("pause");
	return 0;
}


#include <iostream>

using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	if (minPos < maxPos) {
		cout << n - minPos + maxPos - 1;
	}
	else {
		cout << n - minPos + maxPos - 2;
	}

	return 0;
}


#include <iostream>

using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << n - FindMin(a, n) + FindMax(a, n) - 1;
	return 0;
}


#include <iostream>
using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			min = a[i];
			pos = i;

		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			max = a[i];
			pos = i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	//cout << minPos << " " << maxPos << endl;
	if (minPos < maxPos) {
		cout << n - minPos + maxPos - 2;
	}
	else {
		cout << n - minPos + maxPos - 1;
	}
	//system("pause");
	return 0;
}


#include <iostream>
using namespace std;

int FindMin(int *a, int n) {
	int pos = n - 1;
	int min = a[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] < min) {
			int temp = a[i];
			a[i] = min;
			min = temp;
			pos = i;
		}
	}
	return pos;
}

int FindMax(int *a, int n) {
	int pos = 0;
	int max = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] > max) {
			int temp = a[i];
			a[i] = max;
			max = temp;
			pos = (i == n - 1) ? i + 1 : i;
		}
	}
	return pos;
}

int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int minPos = FindMin(a, n);
	int maxPos = FindMax(a, n);
	//cout << minPos << " " << maxPos << endl;
	if (minPos < maxPos) {
		cout << n - minPos + maxPos - 2;
	}
	else {
		cout << n - minPos + maxPos - 1;
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>max){
            max=a[i];
            imax=i+1;
        }
        if(a[i]<min){
            min=a[i];
            imin=i+1;
        }

    }

    int sum=0;

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=(n-imin)+(imax-1)-2;
    }

    cout<<sum;

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>max){
            max=a[i];
            imax=i+1;
        }
        if(a[i]<min){
            min=a[i];
            imin=i+1;
        }

    }

    int sum=0;

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=(n-imin)+(imax-1)-1;
    }

    cout<<sum;

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>max){
            max=a[i];
            imax=i+1;
        }
    }

    for(int i=n; i>0; i--){
        if(a[i]<min){
            min=a[i];
            imin=i+1;
        }
    }

    int sum=0;

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=((n-imin)+(imax-1))-1;
    }

    cout<<sum;

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>=max){
            max=a[i];
            imax=i+1;
        }
        if(a[i]<=min){
            min=a[i];
            imin=i+1;
        }

    }

    int sum=0;

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=(n-imin)+(imax-1)-1;
    }

    cout<<sum;

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>max){
            max=a[i];
            imax=i+1;
        }
        if(a[i]<min){
            min=a[i];
            imin=i+1;
        }

    }

    int sum=0;

    if(imin>imax){
        sum=abs(n-imin)+abs(imax-1);
    }

    if(imax>imin){
        sum=(abs(n-imin)+abs(imax-1))-1;
    }

    cout<<sum;

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>=max){
            max=a[i];
            imax=i+1;
        }
        if(a[i]<=min){
            min=a[i];
            imin=i+1;
        }

    }

    int sum=0;

    if(a[0]==max && a[n-1]==min){
        cout<<"0";
        return 0;
    }

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=(n-imin)+(imax-1)-1;
    }

    cout<<sum;

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>max){
            max=a[i];
            imax=i+1;
        }
    }

    for(int i=n-1; i>-1; i--){
        if(a[i]<min){
            min=a[i];
            imin=i+1;
        }
    }

    int sum=0;

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=((n-imin)+(imax-1))-1;
    }

    cout<<sum;
return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int max=-100;
    int min=1000;
    int imax=0;
    int imin=0;

    for(int i=0; i<n; i++){
        if(a[i]>max){
            max=a[i];
            imax=i+1;
        }
        if(a[i]<min){
            min=a[i];
            imin=i+1;
        }

    }

    int sum=0;

    if(imin>imax){
        sum=(n-imin)+(imax-1);
    }

    if(imax>imin){
        sum=(n-imin)+(imax-1);
    }

    cout<<sum;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
	int sh=1,n,a[1000],counter=0;
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];
	bool ta=false;
	while (ta==false)
	{
		sh=counter;
		for (int i=1; i<n; i++)
			if (a[i]>a[i-1])
			{
				swap(a[i],a[i-1]);
				counter++;

			}
		if (sh==counter)
		{
			cout<<counter;
			cin>>counter;
			return 0;
		}
	}
}


#include <iostream>
using namespace std;
int main ()
{
	int sh=1,n,a[1000],c1,c2,max,min;
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];

	max=a[0];
	min=max;

	for (int i=0; i<n; i++)
	{
		if (max<=a[i])
		{
			max=a[i];
			c1=i;
		}
		if (min>=a[i])
		{
			min=a[i];
			c2=i;
		}
	}
	if (c1>c2)
		cout<<c1+(n-1-c2)-2;
	else
		cout<<c2+(n-2-c1);
	cin>>sh;
	return 0;

}


#include <iostream>
using namespace std;
int main ()
{
	int sh=1,n,a[1000],counter=0;
	for (int i=0; i<n; i++)
		cin>>a[i];
	while (sh!=0)
	{
		sh=counter;
		for (int i=1; i<n; i++)
			if (a[i]>a[i-1])
			{
				swap(a[i],a[i-1]);
				counter++;
			}
		if (sh==counter)
		{
			cout<<counter;
			return 0;
		}
	}
}


#include <iostream>
using namespace std;
int main ()
{
	int sh=1,n,a[1000],c1,c2,max,min;
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];

	max=a[0];
	min=max;

	for (int i=0; i<n; i++)
	{
		if (max<=a[i])
		{
			max=a[i];
			c1=i;
		}
		if (min>=a[i])
		{
			min=a[i];
			c2=i;
		}
	}
	if (c1>c2)
		cout<<c1+(n-2-c2);
	else
		cout<<c1+(n-1-c2);
	cin>>sh;
	return 0;

}