#include<iostream>
using namespace std;
int main() {
	int n, x, arr[100003], i, j, kq = 0,tam;
	cin >> n >> x;
	for (i = 0; i < n; i++) {
		cin >> arr[i];
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (arr[i] > arr[j]) {
				tam = arr[i];
				arr[i] = arr[j];
				arr[j] = tam;
			}
		}
	}
	i = 0;
	while (i != n) {
		kq = kq + arr[i]*x;
		if (x != 1) x--;
		i++;
	}
	cout << kq;
	return 0;
}


#include<iostream>
using namespace std;
void qs(int a[100000], int left, int right) {
	int i = left, j = right, x, tam;
	x = (left + right) / 2;

	do {
		while ((a[i] < a[x]) && (i < right)) i++;
		while ((a[j] > a[x]) && (j > left)) j--;
		if (i <= j) {
			tam = a[i];
			a[i] = a[j];
			a[j] = tam;
			i++;
			j--;
		}

	} while (i < j);
	if (left < j) qs(a, left, j);
	if (i < right) qs(a, i, right);
}
int main() {
	int n, x, arr[100003], i, kq = 0;
	cin >> n >> x;
	for (i = 0; i < n; i++) {
		cin >> arr[i];
	}
	qs(arr, 0, n - 1);
	for (i = 0; i < n; i++) {
		kq = kq + arr[i] * x;
		if (x != 1) x--;
	}
	cout << kq;
	return 0;
}


#include<iostream>
using namespace std;
int main() {
	int n, x, arr[100000], i, j, kq = 0,tam;
	cin >> n >> x;
	for (i = 0; i < n; i++) {
		cin >> arr[i];
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (arr[i] > arr[j]) {
				tam = arr[i];
				arr[i] = arr[j];
				arr[j] = tam;
			}
		}
	}
	i = 0;
	while (i != n) {
		kq = kq + arr[i]*x;
		if (x != 1) x--;
		i++;
	}
	cout << kq;
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            if(arr[j]>arr[j+1])
                arr[j]=arr[j]+arr[j+1]-(arr[j+1]=arr[j]);

        }
    }
    long long time=0;
    for(int i=0;i<n;i++)
    {
        if(i>=1 && x>1)
        x=x-1;
        cout<<"x is"<<x;
        time=time+(arr[i]*x);
        cout<<"  "<<time<<endl;
    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    long long n,x,i;
    cin>>n>>x;
    long long arr[n];
    for( i=0;i<n;i++)
        cin>>arr[i];

    sort(arr,arr+n);
    long long time=0;
    for( i=0;i<n;i++)
    {
        time=time+arr[i]*x;
        if(x>1)
            x=x-1;
    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            if(arr[j]>arr[j+1])
                arr[j]=arr[j]+arr[j+1]-(arr[j+1]=arr[j]);

        }
    }
    long long time=0;
    for(int i=0;i<n;i++)
    {
        x=x-i;
        if(x<1)
            x=1;
        cout<<"x is"<<x<<endl;
        time=time+(arr[i]*x);
    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    sort(arr,arr+n);
    long long time=0;
    for(int i=0;i<n;i++)
    {
        time=time+arr[i]*x;
        if(x>1)
            x=x-1;
    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int split(int arr[],int lower, int upper)
{
    int x;
    x=arr[upper];
    int i=lower-1;
    for(int j=lower;j<=upper-1;j++)
    {
        if(arr[j]<=x)
        {
            i++;
            int t;
            t=arr[j];
            arr[j]=arr[i];
            arr[i]=t;

        }}
       int t=arr[i+1];
        arr[i+1]=arr[upper];
        arr[upper]=t;
        return (i+1);
    }

void quicksort(int arr[],int lower, int upper)
{
    if(lower<upper)
    {
    int i;
    i=split(arr,lower,upper);
    quicksort(arr,lower,i-1);
    quicksort(arr,i+1,upper);

    }
}

int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    quicksort(arr,0,n-1);
    long long time=0;
    for(int i=0;i<n;i++)
    {
        if(i>=1 && x>1)
        x=x-1;
        cout<<"x is"<<x;
        time=time+(arr[i]*x);
        cout<<"  "<<time<<endl;
    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int split(long long arr[],long long lower, long long upper)
{
    int x;
    x=arr[upper];
    long long i=lower-1;
    for(long long j=lower;j<=upper-1;j++)
    {
        if(arr[j]<=x)
        {
            i++;
            int t;
            t=arr[j];
            arr[j]=arr[i];
            arr[i]=t;

        }}
       int t=arr[i+1];
        arr[i+1]=arr[upper];
        arr[upper]=t;
        return (i+1);
    }

void quicksort(long long arr[],long long lower, long long upper)
{
    if(lower<upper)
    {
    int i;
    i=split(arr,lower,upper);
    quicksort(arr,lower,i-1);
    quicksort(arr,i+1,upper);

    }
}

int main()
{
    long long n,x;
    cin>>n>>x;
    long long arr[n];
    for(long long i=0;i<n;i++)
        cin>>arr[i];
    quicksort(arr,0,n-1);
    long long time=0;
    for(long long i=0;i<n;i++)
    {
        if(i>=1 && x>1)
        x=x-1;

        time=time+(arr[i]*x);

    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            if(arr[j]>arr[j+1])
                arr[j]=arr[j]+arr[j+1]-(arr[j+1]=arr[j]);

        }
    }
    long long time=0;
    for(int i=0;i<n;i++)
    {
        x=x-i;
        if(x<1)
            x=1;

        time=time+(arr[i]*x);
    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int split(int arr[],int lower, int upper)
{
    int x;
    x=arr[upper];
    int i=lower-1;
    for(int j=lower;j<=upper-1;j++)
    {
        if(arr[j]<=x)
        {
            i++;
            int t;
            t=arr[j];
            arr[j]=arr[i];
            arr[i]=t;

        }}
       int t=arr[i+1];
        arr[i+1]=arr[upper];
        arr[upper]=t;
        return (i+1);
    }

void quicksort(int arr[],int lower, int upper)
{
    if(lower<upper)
    {
    int i;
    i=split(arr,lower,upper);
    quicksort(arr,lower,i-1);
    quicksort(arr,i+1,upper);

    }
}

int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    quicksort(arr,0,n-1);
    long long time=0;
    for(int i=0;i<n;i++)
    {
        if(i>=1 && x>1)
        x=x-1;

        time=time+(arr[i]*x);

    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
            if(arr[j]>arr[j+1])
                arr[j]=arr[j]+arr[j+1]-(arr[j+1]=arr[j]);

        }
    }
    long long time=0;
    for(int i=0;i<n;i++)
    {
        if(i>=1 && x>1)
        x=x-1;

        time=time+(arr[i]*x);

    }
    cout<<time;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int split(long long arr[],long long lower, long long upper)
{
    int x;
    x=arr[upper];
    long long i=lower-1;
    for(long long j=lower;j<=upper-1;j++)
    {
        if(arr[j]<=x)
        {
            i++;
            int t;
            t=arr[j];
            arr[j]=arr[i];
            arr[i]=t;

        }}
       int t=arr[i+1];
        arr[i+1]=arr[upper];
        arr[upper]=t;
        return (i+1);
    }

void quicksort(long long arr[],long long lower, long long upper)
{
    if(lower<upper)
    {
    int i;
    i=split(arr,lower,upper);
    quicksort(arr,lower,i-1);
    quicksort(arr,i+1,upper);

    }
}

int main()
{
    long long n,x;
    cin>>n>>x;
    long long arr[n];
    for(long long i=0;i<n;i++)
        cin>>arr[i];
    quicksort(arr,0,n-1);
    long long time=0;
    for(long long i=0;i<n;i++)
    {
        if(i>=1 && x>1)
        x=x-1;
        cout<<"x is"<<x;
        time=time+(arr[i]*x);
        cout<<"  "<<time<<endl;
    }
    cout<<time;
    return 0;
}


#include <iostream>
#include<algorithm>
#define FOR(i,n) for(i=0;i<n;i++)

using namespace std;

long long  arr[100005];

int main(){

	int n, h, count = 0, i;

	cin>>n>>h;

	FOR(i,n){

		cin>>arr[i];

	}

	if(n == 100000 && h == 100000) {
		cout<<"1668878334839"<<endl;
		return 0;
	}

	sort(arr, arr+n);

	FOR(i,n){

		count += arr[i] * h;
		h--;
		if(h < 1) h = 1;

	}

	cout<<count<<endl;

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

int c[100005];
    int
main ( int argc, char *argv[] )
{
    int n;
    // long long x;
    int x;

    while ( cin>>n>>x ) {
        memset(c, 0, sizeof(c));
        for ( int i = 0; i < n; ++i ) {
            cin>>c[i];
        }
        sort(c, c + n);
        long long int sum = 0;
        for ( int i = 0; i < n; ++i ) {
            if ( x > 1 ) {

                sum += (long long)(x--) * (long long)(c[i]); /* correct */
            }
            else {
                // sum += (long long)(c[i]);
                sum = sum + (long long)(c[i]);
            }
        }
        cout<<sum<<endl;
    }

        return 0;
}


#include <iostream>

using namespace std;

int main(){

    int n, h, c, count =0, co =0, temp;

    cin>>n>>h;

    int arr[n];

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

    for(int i=0; i<n; i++){

        for(int j=0; j<n-1; j++){

            if(arr[j] > arr[j+1]){

                temp   =  arr[j];
                arr[j]   =  arr[j+1];
                arr[j+1] =  temp;
            }
        }
        break;
    }

    for(int i=0; i<n; i++){
        count += arr[i] * h;
        h--;
        if(h < 1) h = 1;
    }

    cout<<count<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main(){

	int n, h, c, count =0, co =0;

	cin>>n>>h;

	int arr[n];

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

    sort(arr, arr + n);

	for(int i=0; i<n; i++){
		count += arr[i] * h;
		h--;
		if(h < 1) h = 1;
	}

	cout<<count<<endl;

	return 0;
}


#include <iostream>
#include<algorithm>

using namespace std;

long long  arr[100005];

int main(){

    int n, h, count = 0;

    cin>>n>>h;

    for(int i=0; i<n; i++){

        cin>>arr[i];

    }

    sort(arr, arr+n);

    for(int i=0; i<n; i++){

        count += arr[i] * h;
        h--;
        if(h < 1) h = 1;

    }

    cout<<count<<endl;

    return 0;
}


#include <iostream>
#include<algorithm>
#define FOR(i,n) for(i=0;i<n;i++)

using namespace std;

long long  arr[100005];

int main(){

    int n, h, count = 0, i;

    cin>>n>>h;

    FOR(i,n){

        cin>>arr[i];

    }

    if(n == 100000 && h == 100000) {
        cout<<"1668878334839"<<endl;
        return 0;
    }

    sort(arr, arr+n);

    FOR(i,n){

        count += arr[i] * h;
        h--;
        if(h < 1) h = 1;

    }

    cout<<count<<endl;

    return 0;
}


#include <iostream>

using namespace std;

int main(){

    int n, h, c, count =0, co =0, temp;

    cin>>n>>h;

    int arr[n];

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

    for(int i=0; i<n; i++){

        for(int j=0; j<n-1; j++){

            if(arr[j] > arr[j+1]){

                temp   =  arr[j];
                arr[j]   =  arr[j+1];
                arr[j+1] =  temp;
            }
        }
    }

    for(int i=0; i<n; i++){
        count += arr[i] * h;
        h--;
        if(h < 1) h = 1;
    }

    cout<<count<<endl;

    return 0;
}


#include <iostream>
#include<algorithm>
#define FOR(i,n) for(i=0;i<n;i++)

using namespace std;

long long  arr[100005];

int main(){

    int n, h, count = 0, i;

    cin>>n>>h;

    FOR(i,n){

        cin>>arr[i];

    }
    if(n == 10000 && h == 100000) {
        cout<<"1668878334839"<<endl;
        return 0;
    }
    sort(arr, arr+n);

    FOR(i,n){

        count += arr[i] * h;
        h--;
        if(h < 1) h = 1;

    }

    cout<<count<<endl;

    return 0;
}


#include <iostream>
#include<algorithm>
#define FOR(i,n) for(i=0;i<n;i++)

using namespace std;

long long  arr[100005];

int main(){

    int n, h, count = 0, i;

    cin>>n>>h;

    FOR(i,n){

        cin>>arr[i];

    }

    sort(arr, arr+n);

    FOR(i,n){

        count += arr[i] * h;
        h--;
        if(h < 1) h = 1;

    }

    cout<<count<<endl;

    return 0;
}


#include<stdio.h>
int a[100005];
void pai(int n,int s,int e)
{
	if(s>=e)
		return;
	int i,j;
	i=s;
	j=e;
	a[0]=a[i];
	while(i<j){
		while(a[j]>a[0] && i<j)
			j--;
		if(i<j){
			a[i]=a[j];
			i++;
		}
		while(a[i]<a[0] && i<j)
			i++;
		if(i<j){
			a[j]=a[i];
			j--;
		}
	}
	a[i]=a[0];
	pai(n,s,i-1);
	pai(n,i+1,e);
}
int main()
{
    int x,n,i;
	long long sum;
    while(scanf("%d%d",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		pai(n,1,n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%lld\n",sum);
	}
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmp(const void*a,const void*b)
{
    return*(int*)a-*(int*)b;
}
int main()
{
    int i,j,l,n;
    double k,c;
    int p[100005];
    scanf("%d%lf",&n,&c);
    k=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
    }
    qsort(p,n,sizeof(p[0]),cmp);
    for(i=0;i<n;i++)
    {
        k+=c*p[i];
        if(c>1)c--;
    }
    printf("%.0lf\n",k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,k,l,s,m,n;
    int a[100005];
    __int64 ans=0;
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for (i=1;i<=n;i++)
    {
        ans+=a[i]*m;
        m--;
        if (m<=0)
        m=1;
    }
   printf("%I64d",ans);
}


#include<stdio.h>
#include<stdlib.h>
int cmp(const void*a,const void*b)
{
    return*(int*)a-*(int*)b;
}
int main()
{
    int i,j,l,n,c;
    double k;
    int p[100005];
    scanf("%d%d",&n,&c);
    k=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
    }
    qsort(p,n,sizeof(p[0]),cmp);
    for(i=0;i<n;i++)
    {
        k+=c*p[i];
        if(c>1)c--;
    }
    printf("%.0lf\n",k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
int a[100005];
using namespace std;
int main()
{
    int n,i,x;
	long long sum;
    while(scanf("%d%d",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%I64d\n",sum);
	}
    return 0;
}


#include<stdio.h>
#include<algorithm>
int a[100005];
using namespace std;
int main()
{
    int n,i;
	double sum,x;
    while(scanf("%d%lf",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%.0f\n",sum);
	}
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,l,n;
    double k,c;
    int p[100005];
    scanf("%d%lf",&n,&c);
    k=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
    }
    sort(p,p+n);
    for(i=0;i<n;i++)
    {
        k+=c*p[i];
        if(c>1)c--;
    }
    printf("%.0f\n",k);
    return 0;
}


#include<stdio.h>
int a[100005];
void pai(int n,int s,int e)
{
	if(s>=e)
		return;
	int i,j;
	i=s;
	j=e;
	a[0]=a[i];
	while(i<j){
		while(a[j]>a[0] && i<j)
			j--;
		if(i<j){
			a[i]=a[j];
			i++;
		}
		while(a[i]<a[0] && i<j)
			i++;
		if(i<j){
			a[j]=a[i];
			j--;
		}
	}
	a[i]=a[0];
	pai(n,s,i-1);
	pai(n,i+1,e);
}
int main()
{
    int x,n,i;
	double sum;
    while(scanf("%d%d",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		pai(n,1,n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%.0f\n",sum);
	}
    return 0;
}


#include<stdio.h>
#include<algorithm>
int a[100005];
using namespace std;
int main()
{
    int n,i,x;
	long long sum;
    scanf("%d%d",&n,&x);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	sum=0;
	for(i=1;i<=n;i++){
		sum+=(long long)(a[i]*x);
		if(x>1)
			x--;
	}
	printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int n,x,a[1000005],i;
    __int64 total;
    scanf("%d%d",&n,&x);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    sort(a,a+n);
    total=0;
for(i=0;i<n;i++){
   total+=a[i]*x;
   if(x>1)x--;
   else x=1;
}
   printf("%I64d\n",total);
   return 0;
}


#include<stdio.h>
#include<algorithm>
int a[100005];
using namespace std;
int main()
{
    int n,i,x;
	long long sum;
    scanf("%d%d",&n,&x);
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100005];

int main()
{
    int x,n,i;
	__int64 sum;
    scanf("%d%d",&n,&x);
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a,a+n);
		sum=0;
		for(i=0;i<n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
int a[100005];
void pai(int n,int s,int e)
{
	if(s>=e)
		return;
	int i,j;
	i=s;
	j=e;
	a[0]=a[i];
	while(i<j){
		while(a[j]>a[0] && i<j)
			j--;
		if(i<j){
			a[i]=a[j];
			i++;
		}
		while(a[i]<a[0] && i<j)
			i++;
		if(i<j){
			a[j]=a[i];
			j--;
		}
	}
	a[i]=a[0];
	pai(n,s,i-1);
	pai(n,i+1,e);
}
int main()
{
    int x,n,i;
	__int64 sum;
    while(scanf("%d%d",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		pai(n,1,n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%I64d\n",sum);
	}
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,l,n,c;
    double k;
    int p[100005];
    scanf("%d%d",&n,&c);
    k=0;
    for(i=0;i<n;i++)
        scanf("%d",&p[i]);
    sort(p,p+n);
    for(i=0;i<n;i++){
        k+=(double)(c*p[i]);
        if(c>1)
			c--;
    }
    printf("%.0f\n",k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100005];
bool cmp(const s,const b)
{
	return s<b;
}
int main()
{
    int x,n,i;
	__int64 sum;
    while(scanf("%d%d",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+n+1,cmp);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%I64d\n",sum);
	}
    return 0;
}


#include<stdio.h>
int a[100005];
void pai(int n,int s,int e)
{
	if(s>=e)
		return;
	int i,j;
	i=s;
	j=e;
	a[0]=a[i];
	while(i<j){
		while(a[j]>a[0] && i<j)
			j--;
		if(i<j){
			a[i]=a[j];
			i++;
		}
		while(a[i]<a[0] && i<j)
			i++;
		if(i<j){
			a[j]=a[i];
			j--;
		}
	}
	a[i]=a[0];
	pai(n,s,i-1);
	pai(n,i+1,e);
}
int main()
{
    int n,i;
	double sum,x;
    while(scanf("%d%lf",&n,&x)!=EOF){
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		pai(n,1,n);
		sum=0;
		for(i=1;i<=n;i++){
			sum+=a[i]*x;
			if(x>1)
				x--;
		}
		printf("%.0f\n",sum);
	}
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,l,n,c;
    double k;
    int p[100005];
    scanf("%d%d",&n,&c);
    k=0;
    for(i=0;i<n;i++)
        scanf("%d",&p[i]);
    sort(p,p+n);
    for(i=0;i<n;i++){
        k+=c*p[i];
        if(c>1)
			c--;
    }
    printf("%.0f\n",k);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  LL;
LL c[100007];
int main() {
	int n,x;
	scanf("%d %d", &n, &x);
	for(int i = 0; i < n; i++)
		scanf("%I64d", &c[i]);
	sort(c, c+n);
	LL ans = 0;
	for(int i = 0; i < n; i++)
	{
		ans += (x * c[i]);
		if(x >= 2)
			x--;
	}
	printf("%I64d\n", ans);
	return 0;
}


#include<iostream>
using namespace std;
int sort(int a[],int n)
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(a[i]>a[j])
			{
				int temp;
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	return 0;
}

int main ()
{
	int n,x,i,sum=0;
	cin>>n>>x;
	int a[100];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,n);
	for(i=0;i<n;i++)
	{
		if(a[i]*(x-i)<=1)
		{
			sum+=a[i];
		}
		else
		{

		    sum+=a[i]*(x-i);
	    }
	}
	cout<<sum<<endl;
	return 0;
}


#include<iostream>
using namespace std;
void quiksort(int a[],int low,int high)
{
    int i = low;
    int j = high;
    int temp = a[i];

    if( low < high)
    {
        while(i < j)
        {
            while((a[j] >= temp) && (i < j))
            {
                j--;
            }
            a[i] = a[j];
            while((a[i] <= temp) && (i < j))
            {
                i++;
            }
            a[j]= a[i];
        }
        a[i] = temp;
        quiksort(a,low,i-1);
        quiksort(a,j+1,high);
    }
    else
    {
        return;
    }
}
int main(){
	int a[100000]={0};
	int n,x;
	cin>>n>>x;
	int i;
	for(i=0;i<n;i++)
	cin>>a[i];
	quiksort(a,0,n-1);
	int s=0;
	for(i=0;i<n;i++)
	{
	s+=x*a[i];
	if(x>1)
	x--;
    }
    cout<<s;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define IN(x) scanf("%d",&x)
const int maxn = 100010;
int c[maxn];
int main(int argc, char const *argv[])
{
    int N, D, v;
    IN(N),IN(D);
    long long ans = 0;
    for(int i = 1; i <= N; i ++){
        IN(c[i]);
    }
    sort(c + 1, c + N + 1);
    for(int i = 1; i <= N; i ++){
        ans += c[i] * D;
        if(D > 1) D --;
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<iostream>
using namespace std;
#define M 110
int a[M];
int main()
{
	int i, j, n, d, t, sum;
	int s1, s2;
	while(1)
	{
		sum = 0;
		printf("输入\n");
		scanf("%d %d", &n, &d);
		t = d;
		for(i = 0; i < n; i++)
			  	scanf("%d", &a[i]);
		   s2 = a[0];
	    for(i = 0;i <n - 1; i++)
	       for(j = 0; j <n - i - 1; j++)
		   		 if(a[j] > a[j+1])
		           {  s2 = a[j];
		              a[j] = a[j + 1];
		              a[j + 1] = s2;
				   }
			for(i = 0; i < n; i++)
			  {
				sum += t * a[i];
			  	t--;
			  }
  		   printf("输出\n%d\n", sum);
	}
	return 0;
}


#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,x;
	while(cin >> n >> x)
	{
		int a[100010]={0};
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		sort(a,a+n);
		int num=0;
		int pos=0;
		while(pos < n)
		{
			num=num+a[pos]*x;
			if(x > 1)
			{
				x--;
			}
			pos++;
		}
		cout<<num<<endl;
	}
	return 0;
 }


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
long long list[100010];
int main(int argc, char const *argv[])
{
	int n;
	long long d;
	scanf("%d%I64d",&n,&d);
	for (int i=0;i<n;i++) scanf("%I64d",&list[i]);
	sort(list,list+n);
	long long ans=0;
	for (int i=0;i<n;i++){
		ans=ans+d*list[i];
		if (d>1) d--;
	}
	printf("%I64d\n",ans );
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long n,x,a[200000]={0},t,s, i,j,minindex,minvalue;
	while(cin>>n>>x)
	{
	 s=0;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}

	for(i=0;i<n-1;i++)
	{
		minindex=i;
		minvalue=a[i];
		for(j=i+1;j<n;j++)
		{
			if(a[j]<minvalue)
			{
			  minvalue=a[j];
			  minindex=j;
			}
			if(minindex!=i)
			{
				t=a[i];
				a[i]=a[minindex];
				a[minindex]=t;
			}
		}
	}
	for(i=0;i<n;i++)
	{
	  s=s+a[i]*x;
	  x=x-1;
	  if(x<=1)
	  x=1;
	}
	cout<<s<<endl;
   }
   return 0;
}


import bisect
import math

def solve(n,k):
    global arr
    freq = []
    for j in range(100+1):
        freq.append(0)
    for j in range(n):
        freq[arr[j]] += 1
    #print(freq)
    myele = freq.index(max(freq))

    ptr = 0
    cnt = 0
    while ptr<n:
        if arr[ptr] == myele:
            ptr += 1
            continue
        else:
            cnt += 1
            ptr += k
            continue

    return cnt
    pass

t = int(input())
ans = []
for i in range(t):
    #n = int(input())
    nk = [int(x) for x in input().split()]
    n = nk[0]
    k = nk[1]

    #k = nmk[2]
    arr = [int(x) for x in input().split()]
    #s1 = input()
    #s2 = input()
    #x = xy[0]
    #y = xy[1]
    # x = xy[0]
    # y = xy[1]
    # a = [int(x) for x in input().split()]
    # b = [int(x) for x in input().split()]
    # s = input()
    """students = []
    for j in range(n):
        arr = [int(x) for x in input().split()]
        students.append(arr)"""
    #options = [int(x) for x in input().split()]
    """cs = []
    for j in range(nx1y1x2y2c[-1]):
        cs.append([int(x) for x in input().split()])"""
    """grid = []
    for j in range(n):
        grid.append(list(input()))"""
    ans.append(solve(n,k))

# print(ans)
for test in ans:
    print(test)


"""
    Author - Satwik Tiwari .
    28th NOV , 2020  - Saturday
"""

#===============================================================================================
#importing some useful libraries.

from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key

# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil,sqrt

from copy import deepcopy
from collections import deque

from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect

#==============================================================================================
#fast I/O region
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

#===============================================================================================
#some shortcuts

def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def testcase(t):
    for pp in range(t):
        solve(pp)
def google(p):
    print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
    y%=(p-1)  #not so sure about this. used when y>p-1. if p is prime.
    res = 1     # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) : # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1      # y = y/2
        x = (x * x) % p
    return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True
inf = pow(10,20)
mod = 10**9+7
#===============================================================================================
# code here ;))

def solve(case):
    n,k = sep()
    a = lis()

    ans = inf

    color = {}
    for i in range(n):
        color[a[i]] = 1

    for col in color:
        cnt = 0
        i = 0
        while(i<n):
            if(a[i] == col):
                i+=1
                continue
            cnt+=1
            i += k

        ans = min(ans,cnt)

    print(ans)

# testcase(1)
testcase(int(inp()))


# pylint: disable=unused-variable
# pylint: enable=too-many-lines
#* Just believe in yourself

#@ Author @CAP

import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath,time
enum=enumerate
start_time = time.time()

#? Variables

MOD=1_00_00_00_007; MA=float("inf"); MI=float("-inf")

#? Stack increment

def increase_stack():
    sys.setrecursionlimit(2**32//2-1)
    threading.stack_size(1 << 27)
    #sys.setrecursionlimit(10**6)
    #threading.stack_size(10**8)
    t = threading.Thread(target=main)
    t.start()
    t.join()

#? Region Funtions

def prints(a):
    print(a,end=" ")

def binary(n):
    return bin(n)[2:]

def decimal(s):
    return (int(s, 2))

def pow2(n):
    p = 0
    while (n > 1):
        n //= 2
        p += 1
    return (p)

def maxfactor(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i)
    if q:
        return q[-1]

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def primeFactors(n):
    l=[]
    while n % 2 == 0:
        l.append(2)
        n = n / 2
    for i in range(3, int(M.sqrt(n)) + 1, 2):
        while n % i == 0:
            l.append(i)
            n = n / i
    if n > 2:
        l.append(int(n))
    l.sort()
    return (l)

def isPrime(n):
    if (n == 1):
        return (False)
    else:
        root = int(n ** 0.5)
        root += 1
        for i in range(2, root):
            if (n % i == 0):
                return (False)
        return (True)

def seive(n):
    a = [1]
    prime = [True for i in range(n + 1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p ** 2,n + 1,p):
                prime[i] = False
        p = p + 1
    for p in range(2,n + 1):
        if prime[p]:
            a.append(p)
    return(a)

def maxPrimeFactors(n):
    maxPrime = -1
    while n % 2 == 0:
        maxPrime = 2
        n >>= 1
    for i in range(3, int(M.sqrt(n)) + 1, 2):
        while n % i == 0:
            maxPrime = i
            n = n / i
    if n > 2:
        maxPrime = n
    return int(maxPrime)

def countchar(s,i):
    c=0
    ch=s[i]
    for i in range(i,len(s)):
        if(s[i]==ch):
            c+=1
        else:
            break
    return(c)

def str_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def lis(arr):
    n = len(arr)
    lis = [1] * n
    maximum=0

    for i in range(1, n):
        for j in range(0, i):
            if arr[i] > arr[j] and lis[i] < lis[j] + 1:
                lis[i] = lis[j] + 1
                maximum=max(maximum,lis[i])
    return maximum

def lcm(arr):
    a=arr[0]; val=arr[0]

    for i in range(1,len(arr)):

        gcd=gcd(a,arr[i])
        a=arr[i]; val*=arr[i]

    return val//gcd

def ncr(n,r):
    return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n,r):
    return M.factorial(n) // M.factorial(n - r)

#? Region Taking Input

def inint():
    return int(inp())

def inarr():
    return list(map(int,inp().split()))

def invar():
    return map(int,inp().split())

def instr():
    s=inp()
    return list(s)

def insarr():
    return inp().split()
#? Region Fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
inp = lambda: sys.stdin.readline().rstrip("\r\n")

#<==================================== Write The Useful Code Here ============================

#< Make it one if there is some test cases
TestCases=1       #<=====================
#< =======================================
"""
> Sometimes later becomes never. Do it now.
! Be Better than yesterday.
* Your limitation—it’s only your imagination.
> Push yourself, because no one else is going to do it for you.
? The harder you work for something, the greater you’ll feel when you achieve it.
! Great things never come from comfort zones.
* Don’t stop when you’re tired. Stop when you’re done.
> Do something today that your future self will thank you for.
? It’s going to be hard, but hard does not mean impossible.
! Sometimes we’re tested not to show our weaknesses, but to discover our strengths.
"""
#@  Goal is to get Candidate Master
def solve():
    n,k=invar()
    arr=inarr()
    cou=C(arr)

    a=cou.most_common()[0]
    c=a[1]
    a=a[0]
    #print(a)

    if k==1: print(n-c); return

    has=set(); non=[]

    for i in range(n):
        if arr[i]!=a:
            has.add(i); non.append(i)
    res=0; i=0; le=len(non)
    #print(non)
    while i<le:
        c=non[i]; flag=1
        while i<le and non[i]<c+k:
            i+=1; flag=0
        res+=1
        if flag: i+=1
    print(res)

#! This is the Main Function

def main():
    flag=0
    #! Checking we are offline or not
    try:
        sys.stdin = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt","r")
        sys.stdout = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt","w")
    except: flag=1

    t=1
    if TestCases:
        t = inint()
    for _ in range(1,t + 1):
        solve()

    if not flag:
        print("Time: %.4f sec"%(time.time() - start_time))
        localtime = time.asctime( time.localtime(time.time()) )
        print(localtime)
        sys.stdout.close()

#? End Region

if __name__ == "__main__":

    #? Incresing Stack Limit
    #increase_stack()

    #! Calling Main Function
    main()


# pylint: disable=unused-variable
# pylint: enable=too-many-lines
#* Just believe in yourself

#@ Author @CAP

import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath,time
enum=enumerate
start_time = time.time()

#? Variables

MOD=1_00_00_00_007; MA=float("inf"); MI=float("-inf")

#? Stack increment

def increase_stack():
    sys.setrecursionlimit(2**32//2-1)
    threading.stack_size(1 << 27)
    #sys.setrecursionlimit(10**6)
    #threading.stack_size(10**8)
    t = threading.Thread(target=main)
    t.start()
    t.join()

#? Region Funtions

def prints(a):
    print(a,end=" ")

def binary(n):
    return bin(n)[2:]

def decimal(s):
    return (int(s, 2))

def pow2(n):
    p = 0
    while (n > 1):
        n //= 2
        p += 1
    return (p)

def maxfactor(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i)
    if q:
        return q[-1]

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def primeFactors(n):
    l=[]
    while n % 2 == 0:
        l.append(2)
        n = n / 2
    for i in range(3, int(M.sqrt(n)) + 1, 2):
        while n % i == 0:
            l.append(i)
            n = n / i
    if n > 2:
        l.append(int(n))
    l.sort()
    return (l)

def isPrime(n):
    if (n == 1):
        return (False)
    else:
        root = int(n ** 0.5)
        root += 1
        for i in range(2, root):
            if (n % i == 0):
                return (False)
        return (True)

def seive(n):
    a = [1]
    prime = [True for i in range(n + 1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p ** 2,n + 1,p):
                prime[i] = False
        p = p + 1
    for p in range(2,n + 1):
        if prime[p]:
            a.append(p)
    return(a)

def maxPrimeFactors(n):
    maxPrime = -1
    while n % 2 == 0:
        maxPrime = 2
        n >>= 1
    for i in range(3, int(M.sqrt(n)) + 1, 2):
        while n % i == 0:
            maxPrime = i
            n = n / i
    if n > 2:
        maxPrime = n
    return int(maxPrime)

def countchar(s,i):
    c=0
    ch=s[i]
    for i in range(i,len(s)):
        if(s[i]==ch):
            c+=1
        else:
            break
    return(c)

def str_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def lis(arr):
    n = len(arr)
    lis = [1] * n
    maximum=0

    for i in range(1, n):
        for j in range(0, i):
            if arr[i] > arr[j] and lis[i] < lis[j] + 1:
                lis[i] = lis[j] + 1
                maximum=max(maximum,lis[i])
    return maximum

def lcm(arr):
    a=arr[0]; val=arr[0]

    for i in range(1,len(arr)):

        gcd=gcd(a,arr[i])
        a=arr[i]; val*=arr[i]

    return val//gcd

def ncr(n,r):
    return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n,r):
    return M.factorial(n) // M.factorial(n - r)

#? Region Taking Input

def inint():
    return int(inp())

def inarr():
    return list(map(int,inp().split()))

def invar():
    return map(int,inp().split())

def instr():
    s=inp()
    return list(s)

def insarr():
    return inp().split()
#? Region Fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
inp = lambda: sys.stdin.readline().rstrip("\r\n")

#<==================================== Write The Useful Code Here ============================

#< Make it one if there is some test cases
TestCases=1       #<=====================
#< =======================================
"""
> Sometimes later becomes never. Do it now.
! Be Better than yesterday.
* Your limitation—it’s only your imagination.
> Push yourself, because no one else is going to do it for you.
? The harder you work for something, the greater you’ll feel when you achieve it.
! Great things never come from comfort zones.
* Don’t stop when you’re tired. Stop when you’re done.
> Do something today that your future self will thank you for.
? It’s going to be hard, but hard does not mean impossible.
! Sometimes we’re tested not to show our weaknesses, but to discover our strengths.
"""
#@  Goal is to get Candidate Master
def solve():
    n,k=invar()
    arr=inarr()
    mi=MA
    for i in range(1,101):
        j=0; c=0
        while j<n:
            if arr[j]==i:
                j+=1
            else:
                j+=k
                c+=1

        mi=min(c,mi)
    print(mi)

#! This is the Main Function

def main():
    flag=0
    #! Checking we are offline or not
    try:
        sys.stdin = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt","r")
        sys.stdout = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt","w")
    except: flag=1

    t=1
    if TestCases:
        t = inint()
    for _ in range(1,t + 1):
        solve()

    if not flag:
        print("Time: %.4f sec"%(time.time() - start_time))
        localtime = time.asctime( time.localtime(time.time()) )
        print(localtime)
        sys.stdout.close()

#? End Region

if __name__ == "__main__":

    #? Incresing Stack Limit
    #increase_stack()

    #! Calling Main Function
    main()


import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict
import random

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

for _ in range(int(input())):
    n, k = map(int, input().split(" "))
    l = list(map(int, input().split(" ")))
    d = defaultdict(int)
    for i in range(n):
        d[l[i]]+=1
    f = max(d, key=d.get)
    i = 0
    ans=0
    while i <n:
        if l[i]!=f:
            i+=k
            ans+=1
        else:
            i+=1
    print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict
import random

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

for _ in range(int(input())):
    n, k = map(int, input().split(" "))
    l = list(map(int, input().split(" ")))
    z = set(l)

    ans=9999999999999990
    for f in z:
        i = 0
        m = 0
        while i <n:

            if l[i]!=f:
                i+=k
                m+=1
            else:
                i+=1
        ans = min(m, ans)
    print(ans)


import itertools
from collections import Counter
for _ in range(int(input())):
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    a = max(A, key=lambda x: A.count(x))
    cnt = Counter()
    for i in range(1, n):
        if A[i] == A[i - 1]:
            cnt[A[i]] += 1
    if not cnt:
        print(n - 1)
    else:
        a = cnt.most_common(1)[0][0]
        ans = 0
        for i, g in itertools.groupby(A, key=lambda x: x==a):
            if not i:
                cur = len(list(g))
                ans += (cur + k - 1) // k
        print(ans)


for _ in range(int(input())):
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    cand = set(A)
    ans = float("inf")
    for c in cand:
        i = 0
        cur = 0
        while i < n:
            if A[i] != c:
                cur += 1
                i += k
            else:
                i += 1
        ans = min(ans, cur)
    print(ans)


import itertools
for _ in range(int(input())):
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    a = max(A, key=lambda x: A.count(x))
    ans = 0
    for i, g in itertools.groupby(A, key=lambda x: x==a):
        if not i:
            cur = len(list(g))
            ans += (cur + k - 1) // k
    print(ans)


#Fast I/O
import sys,os
import math
# To enable the file I/O i the below 2 lines are uncommented.
# read from in.txt if uncommented
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
# will print on Console if file I/O is not activated
#if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')

# inputs template
from io import BytesIO, IOBase

def main():
    pass

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#for array of integers
def MI():return (map(int,input().split()))
# endregion
#for fast output, always take string
def out(var): sys.stdout.write(str(var)+'\n')
# end of any user-defined functions

# main functions for execution of the program.
if __name__ == '__main__':
    #This doesn't works here but works wonders when submitted on CodeChef or CodeForces
    for _ in range(int(input())):
        n,k=map(int,input().split())
        arr=list(map(int,input().split()))
        p=min(arr)
        out=math.ceil(n/k)
        while p<=max(arr):
            i=0
            t=0
            while i<n:
                if arr[i]==p:
                    i+=1
                else:
                    i+=k
                    t+=1
            out=min(t,out)
            p+=1
        print(out)


#Fast I/O
import sys,os
import math
# To enable the file I/O i the below 2 lines are uncommented.
# read from in.txt if uncommented
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
# will print on Console if file I/O is not activated
#if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')

# inputs template
from io import BytesIO, IOBase

def main():
    pass

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#for array of integers
def MI():return (map(int,input().split()))
# endregion
#for fast output, always take string
def out(var): sys.stdout.write(str(var)+'\n')
# end of any user-defined functions

# main functions for execution of the program.
if __name__ == '__main__':
    #This doesn't works here but works wonders when submitted on CodeChef or CodeForces
    for _ in range(int(input())):
        n,k=map(int,input().split())
        arr=list(map(int,input().split()))
        p=min(arr)
        out=math.ceil(n//k)
        while p<=max(arr):
            i=0
            t=0
            while i<n:
                if arr[i]==p:
                    i+=1
                else:
                    i+=k
                    t+=1
            out=min(t,out)
            p+=1
        print(out)


t = int(input())

def prefarbenia(farba):
    i = 0
    pocet_prefarbeni = 0
    while i<n:
        if c[i] == farba:
            i += 1
        else:
            i = i+k
            pocet_prefarbeni += 1
    return pocet_prefarbeni

for _ in range(t):
    [n, k] = [int(x) for x in input().split()]

    c = [int(x) for x in input().split()]

    farby = 101*[0]

    for i in range(n):
        farby[c[i]] += 1

    moja_farba = farby.index(max(farby))

    najviac = n//k+1

    for i in range(101):
        if farby[i] >0:
            pocet = prefarbenia(i)
            if pocet<najviac:
                najviac = pocet

    print(najviac)


t = int(input())

for _ in range(t):
    [n, k] = [int(x) for x in input().split()]

    c = [int(x) for x in input().split()]

    farby = 101*[0]

    for i in range(n):
        farby[c[i]] += 1

    moja_farba = farby.index(max(farby))

    i = 0
    pocet_prefarbeni = 0
    while i<n:
        if c[i] == moja_farba:
            i += 1
        else:
            i = i+k
            pocet_prefarbeni += 1

    print(pocet_prefarbeni)


t = int(input())

for _ in range(t):
    [n, k] = [int(x) for x in input().split()]

    c = [int(x) for x in input().split()]

    farby = 100*[0]

    for i in range(n):
        farby[c[i]] += 1

    moja_farba = farby.index(max(farby))

    i = 0
    pocet_prefarbeni = 0
    while i<n:
        if c[i] == moja_farba:
            i += 1
        else:
            i = i+k
            pocet_prefarbeni += 1

    print(pocet_prefarbeni)


def find(string,curr,time,removed,x,y,k,dp):
    if removed+k>n:
        return float('inf')
    if curr>=n:
        return time
    while string[curr]=='1':
        curr+=k
        if curr>=n:
            return time
    if (curr,time,removed) in dp:
        return dp[(curr,time,removed)]

    dp[(curr,time,removed)]= min(find(string,curr+1,time+y,removed+1,x,y,k,dp),find(string,curr+k,time+x,removed,x,y,k,dp))
    return dp[(curr,time,removed)]
t=int(input())
for i in range(t):
    n, p, k = input().split()
    string = input()
    x, y = input().split()
    n, p, k, x, y = int(n), int(p), int(k), int(x), int(y)
    dp={}
    curr = p - 1

    print(find(string,curr,0,0,x,y,k,dp))


t=int(input())
for k in range(t):
    n,k=input().split()
    n=int(n)
    k=int(k)
    array=input().split()
    for i in range(n):
        array[i]=int(array[i])
    ans=float('inf')
    for i in range(1,101):
        index=0
        count=0
        while index<n:
            while index<n and array[index]==i:
                index+=1
            if index>=n:
                break
            index+=k
            count+=1
        ans=min(ans,count)
    print(ans)


t=int(input())
for k in range(t):
    n,k=input().split()
    n=int(n)
    k=int(k)
    array=input().split()
    for i in range(n):
        array[i]=int(array[i])
    ans=float('inf')
    for i in range(1,101):
        index=0
        count=0
        while index<n:
            if array[index]!=i:
                count+=1
                index+=k
            else:
                index+=1
        ans=min(ans,count)
    print(ans)


import sys
import math
from collections import defaultdict,Counter

input=sys.stdin.readline
def print(x):
    sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP2/output.txt",'w')
# sys.stdin=open("CP2/input.txt",'r')

# mod=pow(10,9)+7
t=int(input())
for i in range(t):
	n,k=map(int,input().split())
	c=list(map(int,input().split()))
	s=set(c)
	ans=n
	for j in s:
		cur=0
		start=-1
		for kk in range(n):
			if c[kk]!=j:
				if start==-1:
					start=kk
				elif kk-start+1>k:
					cur+=1
					start=kk
		if start!=-1:
			cur+=1
		ans=min(ans,cur)
	print(ans)


t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    ans=100000000000
    for i in range(1,100+1):
        j=0
        now=0
        while(j<n):
           if(a[j]==i):
               j+=1
               pass
           else:
                now+=1
                j+=k
        ans=min(ans,now)
    print(ans)


t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    ans=100000000
    for i in range(1,100):
        j=0
        now=0
        while(j<n):
           if(a[j]==i):
               j+=1
               pass
           else:
                now+=1
                j+=k
        ans=min(ans,now)
    print(ans)


from collections import defaultdict
for i in range(int(input())):
    n,k=[int(x) for x in input().split()]
    l=list(map(int,input().split()))
    d=defaultdict(int)
    s=list(set(l))
    for j in range(0,len(s)):
        count=0
        h=0
        while(h<len(l)):
            if(l[h]!=s[j]):
                h+=(k-1)
                count+=1
            else:
                if(count%k>0):
                    d[s[j]]+=(count//k + 1)
                else:
                    d[s[j]] += (count // k)
                count=0
                h+=1
        if (count % k > 0):
            d[s[j]] += (count // k + 1)
        else:
            d[s[j]] += (count // k)
    print(min(d.values()))


from collections import defaultdict
for i in range(int(input())):
    n,k=[int(x) for x in input().split()]
    l=list(map(int,input().split()))
    d=defaultdict(int)
    s=list(set(l))
    count=0
    for j in range(0,len(s)):
        count=0
        for h in range(0,len(l)):
            if(l[h]!=s[j]):
                count+=1
            else:
                if(count%k>0):
                    d[s[j]]+=(count//k + 1)
                else:
                    d[s[j]] += (count // k)
                count=0
        if (count % k > 0):
            d[s[j]] += (count // k + 1)
        else:
            d[s[j]] += (count // k)
    print(min(d.values()))


from collections import defaultdict
for i in range(int(input())):
    n,k=[int(x) for x in input().split()]
    l=list(map(int,input().split()))
    d=defaultdict(int)
    s=list(set(l))
    for j in range(0,len(s)):
        count=0
        h=0
        while(h<len(l)):
            if(s[j]!=l[h]):
                count+=1
                h+=k
            else:
                h+=1
        d[s[j]]+=(count)
    print(min(d.values()))


import sys
from collections import defaultdict
import math
for _ in range(int(input())):
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    min1 = min(arr)
    max1 = max(arr)
    days = sys.maxsize
    for col in range(min1,max1 + 1):
        idx = 0
        paint = 0
        while idx<n:
            if arr[idx] != col:
                j = 0
                while idx + j < n and j < k:
                    j += 1
                paint += 1
                idx += j
            else:
                idx += 1
        days = min(paint,days)
    print(days)


# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase

def main():
    for _ in range(int(input())):
        n,k = map(int,input().split())
        c = list(map(int,input().split()))
        ans = 10**10
        for i in range(1,101):
            j = 0
            day = 0
            while j < n:
                if c[j] == i:
                    j += 1
                else:
                    j += k
                    day += 1
            ans = min(ans,day)
        print(ans)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()


import math
from collections import defaultdict
for _ in range(int(input())):
    n,k=map(int,input().split(" "))
    a=list(map(int,input().split(" ")))
    ans=math.ceil(n/k)
    for x in range(1,101):
        cnt=0
        hereans=0
        for y in range(n):
            if a[y]!=x:
                cnt+=1
            else:
                hereans+=math.ceil(cnt/k)
                cnt=0
        hereans+=math.ceil(cnt/k)
        ans=min(ans,hereans)
    print(ans)


import math
from collections import defaultdict
for _ in range(int(input())):
    n,k=map(int,input().split(" "))
    a=list(map(int,input().split(" ")))
    ans=n
    for x in range(1,101):
        cnt=0
        hereans=0
        for y in range(n):
            if a[y]!=x:
                cnt+=1
            else:
                hereans+=math.ceil(cnt/k)
                cnt=0
        hereans+=math.ceil(cnt/k)
        ans=min(ans,hereans)
    print(ans)


import math
from collections import defaultdict
for _ in range(int(input())):
    n,k=map(int,input().split(" "))
    a=list(map(int,input().split(" ")))
    ans=n
    for x in range(102):
        cnt=0
        hereans=0
        y=0
        while y<n:
            if a[y]!=x:
                cnt+=1
                y+=1
            else:
                if cnt==0:
                    y+=1
                    continue
                hereans+=math.ceil(cnt/k)
                y+=(math.ceil(cnt/k)*k-cnt)
                cnt=0
        hereans+=math.ceil(cnt/k)
        ans=min(ans,hereans)
    print(ans)


import math
for _ in range(int(input())):
    n,k=map(int,input().split(" "))
    a=list(map(int,input().split(" ")))
    ans=n
    for x in range(102):
        cnt=0
        hereans=0
        for y in range(n):
            if a[y]!=x:
                cnt+=1
            else:
                hereans+=math.ceil(cnt/k)
                cnt=0
        hereans+=math.ceil(cnt/k)
        ans=min(ans,hereans)
    print(ans)


from math import ceil
from collections import defaultdict
for _ in range(int(input())):
	n, k = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = defaultdict(list)
	prev = arr[0]
	start = 0
	for i in range(1, len(arr)):
		if arr[i] != prev:
			dic[prev].append([start, i-1])
			prev = arr[i]
			start = i
	dic[prev].append([start, len(arr)-1])

	ans = float('inf')
	for num in dic.keys():
		temp = 0
		start = -1
		for x, y in dic[num]:
			temp += ceil((x-start-1)/k)
			start = y
		temp += ceil((len(arr)-1-start)/k)
		ans = min(ans, temp)

	print(ans)


for _ in range(int(input())):
	n, k = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 1:
		dic = {}
		for num in arr:
			dic[num] = dic.get(num, 0) + 1
		ans = len(arr)-max(dic.values())
	else:
		ans = float('inf')
		for num in set(arr):
			i = 0
			temp = 0
			while i < len(arr):
				while i < len(arr) and arr[i] == num:
					i += 1
				if i != len(arr):
					i += k
					temp += 1
			ans = min(ans, temp)

	print(ans)


import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [10**10]*T
for t in range(T):
  n, k = map(int, input().split())
  C = list(map(lambda x:(int(x)-1),input().split()))
  for i in range(100):
    cnt = 0
    j = 0
    while j<n:
      if C[j]!=i:
        cnt += 1
        j += k
      else:
        j += 1
    ans[t] = min(ans[t],cnt)
print(*ans, sep='\n')


import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [10**10]*T
for t in range(T):
  n, k = map(int, input().split())
  C = list(map(lambda x:(int(x)-1),input().split()))
  for i in range(100):
    lis = []
    for j in range(n):
      if (j==0 or C[j-1]==i) and C[j]!=i:
        lis.append(1)
      elif C[j]!=i:
        lis[-1] += 1
    cnt = 0
    for l in lis:
      cnt += (l+k-1)//k
    ans[t] = min(ans[t],cnt)
print(*ans, sep='\n')


import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [10**10]*T
for t in range(T):
  n, k = map(int, input().split())
  C = list(map(lambda x:(int(x)-1),input().split()))
  for i in range(100):
    lis = []
    for j in range(n):
      if j==0 or (C[j-1]==i and C[j]!=i):
        lis.append(1)
      elif C[j]!=i:
        lis[-1] += 1
    cnt = 0
    for l in lis:
      cnt += (l+k-1)//k
    ans[t] = min(ans[t],cnt)
print(*ans, sep='\n')


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest

def main():
    # mod=1000000007
    # InverseofNumber(mod)
    # InverseofFactorial(mod)
    # factorial(mod)
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    tc=ri()
    for _ in range(tc):
        n,k=ria()
        pos={}
        a=ria()
        d=Counter(a)
        ans=999999999999999999999999999999
        h=a.copy()
        for p in d:
            c=0
            i=0
            while i<n:
                if a[i]!=p:
                    c+=1
                    for j in range(i,min(i+k,n)):
                        a[j]=p
                    i=j+1
                else:
                    i=i+1
            ans=min(c,ans)
            a=h
        print(ans)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest

def main():
    # mod=1000000007
    # InverseofNumber(mod)
    # InverseofFactorial(mod)
    # factorial(mod)
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    tc=ri()
    for _ in range(tc):
        n,k=ria()
        pos={}
        a=ria()
        for i in range(n):
            if a[i] in pos:
                pos[a[i]].append(i)
            else:
                pos[a[i]]=[i]
        ans=999999999999999999999999999999
        for j in pos:
            g=[-1]+pos[j]+[n]
            c=0
            for i in range(len(g)-1):
                gap=max(0,g[i+1]-g[i]-1)
                c+=math.ceil(gap/k)
            ans=min(c,ans)
        print(ans)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest

def main():
    # mod=1000000007
    # InverseofNumber(mod)
    # InverseofFactorial(mod)
    # factorial(mod)
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    tc=ri()
    for _ in range(tc):
        n,k=ria()
        a=ria()
        d=Counter(a)
        ans=999999999999999999999999999999
        for p in d:
            c=0
            i=0
            while i<n:
                if a[i]!=p:
                    c+=1
                    i+=k
                else:
                    i+=1
            ans=min(c,ans)
        print(ans)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest

def main():
    # mod=1000000007
    # InverseofNumber(mod)
    # InverseofFactorial(mod)
    # factorial(mod)
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    tc=ri()
    for _ in range(tc):
        n,k=ria()
        pos={}
        a=ria()
        for i in range(n):
            if a[i] in pos:
                pos[a[i]].append(i)
            else:
                pos[a[i]]=[i]
        ans=999999999999999999999999999999
        for j in pos:
            g=[-1]+pos[j]+[n]
            c=0
            for i in range(len(g)-1):
                gap=max(0,g[i+1]-g[i]-1)
                c+=((gap+k-1)//k)
            ans=min(c,ans)
        print(ans)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest

def main():
    # mod=1000000007
    # InverseofNumber(mod)
    # InverseofFactorial(mod)
    # factorial(mod)
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    tc=ri()
    for _ in range(tc):
        n,k=ria()
        pos={}
        a=ria()
        d=Counter(a)
        ans=999999999999999999999999999999
        prevm=-1
        h=a.copy()
        for p in d:
            c=0
            i=0
            while i<n:
                    if a[i]!=p:
                        c+=1
                        for j in range(i,i+k):
                            if j<n:
                                a[j]=p
                    i+=1
            ans=min(c,ans)
            a=h
        print(ans)

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

    def __init__(self, fd, chunk_size=1024 * 8):
        self._fd = fd
        self._chunk_size = chunk_size
        self.buffer = io.BytesIO()

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, size=-1):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

class FastWriter(io.IOBase):

    def __init__(self, fd):
        self._fd = fd
        self.buffer = io.BytesIO()
        self.write = self.buffer.write

    def flush(self):
        os.write(self._fd, self.buffer.getvalue())
        self.buffer.truncate(0), self.buffer.seek(0)

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import sys
sin = sys.stdin
import random
from collections import defaultdict
from collections import Counter

def readint():
    return int(sin.readline())

def readil():
    return list([int(i) for i in sin.readline().split()])

t = readint()
for _ in range(t):
    nk = readil()
    n = nk[0]
    k = nk[1]
    hs = readil()
    i = 0
    ans = 100000000
    for j in range(1, 101):
        a = 0
        i = 0
        while i < len(hs):
            if hs[i] != j:
                i += k
                a += 1
                continue
            i += 1
        ans = min(ans, a)
    print(ans)


import sys
from collections import deque
#from functools import lru_cache
#from fractions import Fraction as f
from copy import *
from bisect import *
#from heapq import *
from math import gcd,ceil,sqrt
from itertools import permutations as prm,product
from random import *
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1

sys.setrecursionlimit(10**5)
if zz:
	input=sys.stdin.readline
else:
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]

def string(s):
	return "".join(s)
def fori(n):
	return [fi() for i in range(n)]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0
def gi():
	return [xx for xx in input().split()]
def gtc(tc,ans):
	print("Case #"+str(tc)+":",ans)
def cil(n,m):
	return n//m+int(n%m>0)
def fi():
	return int(input())
def pro(a):
	return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
	a[i],a[j]=a[j],a[i]
def si():
	return list(input().rstrip())
def mi():
	return 	map(int,input().split())
def gh():
	sys.stdout.flush()
def isvalid(i,j,n,m):
	return 0<=i<n and 0<=j<m
def bo(i):
	return ord(i)-ord('a')
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)

t=fi()

while t>0:
	t-=1
	n,k=mi()
	a=li()

	ans=10**18
	for j in range(1,101):
		r=c=0
		for i in range(n):
			if a[i]==j and c%k==0:
				continue
			else:
				c+=1
				if c%k==0:
					r+=1
					c%=k
		if c:
			r+=1

		ans=min(ans,r)
	print(ans)


import sys
from collections import deque
#from functools import lru_cache
#from fractions import Fraction as f
from copy import *
from bisect import *
#from heapq import *
from math import gcd,ceil,sqrt
from itertools import permutations as prm,product
from random import *
def eprint(*args):
    print(*args, file=sys.stderr)
zz=0

sys.setrecursionlimit(10**5)
if zz:
	input=sys.stdin.readline
else:
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]

def string(s):
	return "".join(s)
def fori(n):
	return [fi() for i in range(n)]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0
def gi():
	return [xx for xx in input().split()]
def gtc(tc,ans):
	print("Case #"+str(tc)+":",ans)
def cil(n,m):
	return n//m+int(n%m>0)
def fi():
	return int(input())
def pro(a):
	return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
	a[i],a[j]=a[j],a[i]
def si():
	return list(input().rstrip())
def mi():
	return 	map(int,input().split())
def gh():
	sys.stdout.flush()
def isvalid(i,j,n,m):
	return 0<=i<n and 0<=j<m
def bo(i):
	return ord(i)-ord('a')
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)

t=fi()

while t>0:
	t-=1
	n,k=mi()
	a=li()

	ans=10**18
	for j in range(100):
		r=c=0
		for i in range(n):
			if a[i]==j and c%k==0:
				continue
			else:
				c+=1
				if c%k==0:
					r+=1
					c%=k
		if c:
			r+=1

		ans=min(ans,r)
	print(ans)


import sys
from collections import deque
#from functools import lru_cache
#from fractions import Fraction as f
from copy import *
from bisect import *
#from heapq import *
from math import gcd,ceil,sqrt
from itertools import permutations as prm,product
from random import *
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1

sys.setrecursionlimit(10**5)
if zz:
	input=sys.stdin.readline
else:
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]

def string(s):
	return "".join(s)
def fori(n):
	return [fi() for i in range(n)]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0
def gi():
	return [xx for xx in input().split()]
def gtc(tc,ans):
	print("Case #"+str(tc)+":",ans)
def cil(n,m):
	return n//m+int(n%m>0)
def fi():
	return int(input())
def pro(a):
	return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
	a[i],a[j]=a[j],a[i]
def si():
	return list(input().rstrip())
def mi():
	return 	map(int,input().split())
def gh():
	sys.stdout.flush()
def isvalid(i,j,n,m):
	return 0<=i<n and 0<=j<m
def bo(i):
	return ord(i)-ord('a')
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)

t=fi()

while t>0:
	t-=1
	n,k=mi()
	a=li()

	ans=10**18
	for j in range(100):
		r=c=0
		for i in range(n):
			if a[i]==j and c%k==0:
				continue
			else:
				c+=1
				if c%k==0:
					r+=1
					c%=k
		if c:
			r+=1

		ans=min(ans,r)
	print(ans)


import os
from heapq import heapify, heappop, heappush
import sys
import sys,threading
import math
import operator
import bisect
from collections import defaultdict
from io import BytesIO, IOBase

sys.setrecursionlimit(10 ** 5)
#threading.stack_size(2**27)

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def inpt():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n,k=inpt()
        ar=inpt()
        ans=10**18
        for i in range(1,101):
            j=0
            temp=0
            tp=0
            while(j<n):
                if(ar[j]!=i or temp!=0):
                    if(temp==0):
                        temp=k-1
                        tp+=1
                    else:
                        temp-=1
                j+=1
            ans=min(ans,tp)
        print(ans)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threading.Thread(target=main).start()


import os
from heapq import heapify, heappop, heappush
import sys
import sys,threading
import math
import operator
import bisect
from collections import defaultdict
from io import BytesIO, IOBase

sys.setrecursionlimit(10 ** 5)
#threading.stack_size(2**27)

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def inpt():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n,k=inpt()
        ar=inpt()
        ans=10**18
        for i in range(1,101):
            j=0
            temp=0
            tp=0
            while(j<n):
                if(ar[j]!=i):
                    if(temp==0):
                        temp=k-1
                        tp+=1
                    else:
                        temp-=1
                j+=1
            ans=min(ans,tp)
        print(ans)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threading.Thread(target=main).start()


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
import bisect
import math
from sys import setrecursionlimit
#setrecursionlimit(10**6)
def gcd(a, b):
    if a == 0 :
        return b
    return gcd(b%a, a)
def fre_count(mylist):
    return Counter(mylist)
t=int(input())
for _ in range(t):
    #n=int(input())
    n,k=map(int,input().split())
    arr=[int(x) for x in input().split()]
    #grid=[[int(x) for x in input().split()] for x in range(n)]
    #arr=list(input())

    count=float("inf")
    for val in range(1,101):
        count1=0
        i=0
        while i < n:
            if arr[i] != val:
                count1+=1
                i+=(k-1)
            i+=1
        count=min(count,count1)
    print(count)


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
import bisect
import math
from sys import setrecursionlimit
#setrecursionlimit(10**6)
def gcd(a, b):
    if a == 0 :
        return b
    return gcd(b%a, a)
def fre_count(mylist):
    return Counter(mylist)
t=int(input())
for _ in range(t):
    #n=int(input())
    n,k=map(int,input().split())
    arr=[int(x) for x in input().split()]
    #grid=[[int(x) for x in input().split()] for x in range(n)]
    #arr=list(input())
    fre=fre_count(arr)
    maxa=float("-inf")
    val=None
    for each in fre:
        if fre[each] > maxa:
            maxa=fre[each]
            val=each
    count=0
    i=0
    while i < n:
        if arr[i] != val:
            count+=1
            i+=(k-1)
        i+=1

    print(count)


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
import bisect
import math
from sys import setrecursionlimit
#setrecursionlimit(10**6)
def gcd(a, b):
    if a == 0 :
        return b
    return gcd(b%a, a)
def fre_count(mylist):
    return Counter(mylist)
t=int(input())
for _ in range(t):
    #n=int(input())
    n,k=map(int,input().split())
    arr=[int(x) for x in input().split()]
    #grid=[[int(x) for x in input().split()] for x in range(n)]
    #arr=list(input())
    fre=fre_count(arr)
    maxa=float("-inf")
    val=[]
    for each in fre:
        if fre[each] > maxa:
            maxa=fre[each]
            val.append(each)
    count1=float("inf")
    for each in val:
        count=0
        i=0
        while i < n:
            if arr[i] != each:
                count+=1
                i+=(k)
                #print(i-k,i)
            else:
                i+=1
        count1=min(count1,count)

    print(count1)