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)
    li=val
    val=li[-1]
    count=0
    i=0
    while i < n:
        if arr[i] != val:
            count+=1
            i+=(k)
            #print(i-k,i)
        else:
            i+=1
    try:
        val=li[-2]
    except:
        val=li[-1]
    count1=0
    i=0
    while i < n:
        if arr[i] != val:
            count1+=1
            i+=(k)
            #print(i-k,i)
        else:
            i+=1
    print(min(count,count1))


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)
    li=val
    val=li[-1]
    count=0
    i=0
    while i < n:
        if arr[i] != val:
            count+=1
            i+=(k)
            #print(i-k,i)
        else:
            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)
    fre[arr[0]]-=1
    fre[arr[-1]]-=1
    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

    count1=0
    val=arr[0]
    i=0
    while i < n:
        if arr[i] != val:
            count1+=1
            i+=(k-1)
        i+=1
    count=min(count,count1)

    count1=0
    val=arr[-1]
    i=0
    while i < n:
        if arr[i] != val:
            count1+=1
            i+=(k-1)
        i+=1
    count=min(count,count1)
    print(count)


for t in range(int(input())):
    n, k = map(int, input().rstrip().split())
    a = list(map(int, input().rstrip().split()))
    ans = 10**6
    for i in range(1, 101): # colors from 1 to 100
        j, t = 0, 0
        while j < n: # n up to 10^5
            if a[j] == i:
                j+=1 # the house is already painted correctly for color i
            else:
                t+=1 # paint the house and the next k houses
                j+=k
        ans = min(ans,t)
    print(ans)


from collections import Counter
for t in range(int(input())):
    n, k = map(int, input().rstrip().split())
    a = list(map(int, input().rstrip().split()))
    #n = int(input())
    c = Counter(a)
    m = c.most_common(1)[0]
    common_color = m[0]
    number_color = m[1]
    count1 = 0
    count2 = 0
    count3 =(n-number_color)//k+int((n-number_color)%k!=0)
    b = a[::-1]

    for x in range(n):
        if a[x] != common_color:
            if n-x <k:
                a[x:] = [common_color]*(n-x)
            else:
                #print(a[x:x+k])
                a[x:x+k] = [common_color]*(k)
            count1+=1
        if b[x] != common_color:
            if n-x <k: b[x:] = [common_color]*(n-x)
            else: b[x:x+k] = [common_color]*(k)
            count2+=1

    print(min(count1,count2))


from collections import Counter
for t in range(int(input())):
    n, k = map(int, input().rstrip().split())
    a = list(map(int, input().rstrip().split()))
    #n = int(input())
    c = Counter(a)
    m = c.most_common(1)[0]
    common_color = m[0]
    number_color = m[1]
    count1 = 0
    count2 = 0
    print((n-number_color)//k+int((n-number_color)%k!=0))
    """
    for x in range(n):
        if a[x] != common_color:
            a[x:x+k-1] = common_color
            count1+=1
    a = a[::-1]
    for x in range(n):
        if a[x] != common_color:
            a[x:x+k-1] = common_color
            count2+=1
    print(count1,count2)
    """


from collections import Counter
for t in range(int(input())):
    n, k = map(int, input().rstrip().split())
    a = list(map(int, input().rstrip().split()))
    #n = int(input())
    c = Counter(a)
    m = c.most_common(1)[0]
    common_color = m[0]
    number_color = m[1]
    count1 = 0
    count2 = 0
    count3 =(n-number_color)//k+int((n-number_color)%k!=0)
    b = a[::-1]

    for x in range(n):
        if a[x] != common_color:
            if n-x <k:
                a[x:] = [common_color]*(n-x)
            else:
                #print(a[x:x+k])
                a[x:x+k] = [common_color]*(k)
            count1+=1
        if b[x] != common_color:
            if n-x <k: b[x:] = [common_color]*(n-x)
            else: b[x:x+k] = [common_color]*(k)
            count2+=1

    print(min(count1,count2,count3))


t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    c=list(map(int,input().split()))
    m=10000
    for i in range(1,101):
        cnt=0
        j=0
        while(j<n):
            if(c[j]!=i):
                cnt+=1
                j+=k
            else:
                j+=1
        m=min(cnt,m)
    print(m)


t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    c=list(map(int,input().split()))
    m=1000000000
    for i in range(1,101):
        cnt=0
        j=0
        while(j<n):
            if(c[j]!=i):
                cnt+=1
                j+=k
            else:
                j+=1
        m=min(cnt,m)
    print(m)


import math

def repainting_streets():
    for _ in range(int(input())):
        n, k = [int(x) for x in input().split(' ')]
        arr = [int(x) for x in input().split(' ')]
        arr += [0]
        min_count = 10000000
        for i in range(1, 101):
            arr[n] = i
            count = 0
            nr_char = 0
            idx = 0
            while idx < len(arr):
                if arr[idx] == i:
                    curr = math.ceil(nr_char / k)
                    count += curr
                    idx += max(curr * k - nr_char - 1, 0)
                    nr_char = 0
                else:
                    nr_char += 1
                idx += 1
            if count < min_count:
                min_count = count
        print(min_count)

if __name__ == "__main__":
    repainting_streets()


import math

def repainting_streets():
    for _ in range(int(input())):
        n, k = [int(x) for x in input().split(' ')]
        arr = [int(x) for x in input().split(' ')]
        arr += [0]
        min_count = 10000000
        for i in range(1, 101):
            arr[n] = i
            count = 0
            nr_char = 0
            idx = 0
            while idx < len(arr):
                if arr[idx] == i:
                    curr = math.ceil(nr_char / k)
                    count += curr
                    idx += curr * k - nr_char
                    nr_char = 0
                else:
                    nr_char += 1
                idx += 1
            if count < min_count:
                min_count = count
        print(min_count)

if __name__ == "__main__":
    repainting_streets()


import java.io.PrintWriter
import java.util.*
import kotlin.math.min

fun main() = tm {
    repeat(readInt()) {
        val numHouses = readInt()
        val cap = readInt()

        val cols = IntArray(numHouses) { readInt() }

        var min = Int.MAX_VALUE
        for (i in 1..100) {
            var idx = 0
            var steps = 0
            outer@while (idx < numHouses) {
                while (cols[idx] == i) {
                    if (++idx == numHouses) {
                        break@outer
                    }
                }
                idx += cap
                ++steps
            }
            min = min(min, steps)
        }
        println(min)
    }
}

private inline fun <T> tm(block: R687BIO.() -> T) {
    R687BIO().use(block)
}

private class R687BIO : AutoCloseable, PrintWriter(System.out.bufferedWriter(), false) {
    private val r = System.`in`.bufferedReader()
    private var tk = StringTokenizer("")

    fun readWord(): String {
        while (!tk.hasMoreTokens()) {
            tk = StringTokenizer(r.readLine() ?: return "", " ")
        }
        return tk.nextToken()
    }

    fun clearLine() { tk = StringTokenizer("") }
    fun readLine() = r.readLine()
    fun readInt() = readWord().toInt()
    fun readDouble() = readWord().toDouble()
    fun readLong() = readWord().toLong()
    override fun close() = flush()
}


import kotlin.math.abs

fun main() {
    val r = System.`in`.bufferedReader()
    val sb = StringBuilder()
    repeat(r.readLine().toInt()) {
        val (n, k) = r.readLine().split(" ").map { it.toInt() }
        val v = r.readLine().split(" ").map { it.toInt() }
        var min = Int.MAX_VALUE
        for (color in 1..100) {
            var i = 0
            var cnt = 0
            while (i <= n - 1) {
                if (v[i] != color) {
                    cnt++
                    i += k
                }else{
                    i++
                }
            }
            min = minOf(min, cnt)
        }
        sb.appendln(min)
    }
    print(sb)
}


import kotlin.collections.*
import kotlin.math.*

fun readInts() = readLine()!!.split(" ").map{i -> i.toInt()}.toMutableList()
fun readInt() = readLine()!!.toInt()
fun readLongs() = readLine()!!.split(" ").map{i -> i.toLong()}.toMutableList()

fun main() {
    val t = readInt()
    repeat(t) {
        val (n, k) = readInts()
        val street = readInts()
        val set = street.toSet()
        var ans = n - 1
        for (i in set) {
            var j = 0
            var localAns = 0
            while (j < n) {
                if (street[j] == i) {
                    j++
                } else {
                    j += k
                    localAns++
                }
            }
            ans = min(localAns, ans)
        }
        println(ans)
    }
}


import java.util.*
import kotlin.collections.*
import kotlin.math.*

fun readInts() = readLine()!!.split(" ").map{i -> i.toInt()}.toMutableList()
fun readInt() = readLine()!!.toInt()
fun readLongs() = readLine()!!.split(" ").map{i -> i.toLong()}.toMutableList()

fun main() {
    val t = readInt()
    repeat(t) {
        val (n, k) = readInts()
        val street = readInts()
        val map = HashMap<Int, Int>()
        var i = 1
        while(i < n) {
            if (i > 0 && street[i - 1] == street[i]) {
                var j = i + 1
                var length = 2
                while (j < n && street[j - 1] == street[j]) {
                    j++
                    length++
                }
                map[street[i]] = map.getOrDefault(street[i], 0) + length
                i = j
            }
            i++
        }
        val max = if(map.isNotEmpty()) map.values.max()!! else 1
        println(ceil((n - max).toDouble() / k).toInt())
    }
}


import java.util.*
import kotlin.collections.*
import kotlin.math.*

fun readInts() = readLine()!!.split(" ").map{i -> i.toInt()}.toMutableList()
fun readInt() = readLine()!!.toInt()
fun readLongs() = readLine()!!.split(" ").map{i -> i.toLong()}.toMutableList()

fun main() {
    val t = readInt()
    repeat(t) {
        val (n, k) = readInts()
        val street = readInts()
        val map = HashMap<Int, Int>()
        var i = 1
        while(i < n) {
            if (i > 0 && street[i - 1] == street[i]) {
                var j = i + 1
                var length = 2
                while (j < n && street[j - 1] == street[j]) {
                    j++
                    length++
                }
                map[street[i]] = map.getOrDefault(street[i], 0) + length
                i = j
            } else {
                i++
            }
        }
        val maxValue = if(map.isNotEmpty()) map.maxWith(kotlin.Comparator{k1, k2 -> map[k1.key]!!.compareTo(map[k2.key]!!)})!!.key else -1
        val max = if(map.isNotEmpty()) map[maxValue]!! else 1
        var ans = 0
        i = if(maxValue == -1) 1 else 0
        while (i < n) {
            if (street[i] == maxValue) {
                i++
            } else {
                ans++
                i += k
            }
        }
        println(if(street[0] == street[n - 1] && n - max == 2) 1 else ans)
    }
}


import kotlin.collections.*
import kotlin.math.*

fun readInts() = readLine()!!.split(" ").map{i -> i.toInt()}.toMutableList()
fun readInt() = readLine()!!.toInt()
fun readLongs() = readLine()!!.split(" ").map{i -> i.toLong()}.toMutableList()

fun main() {
    val t = readInt()
    repeat(t) {
        val (n, k) = readInts()
        val street = readInts()
        val map = HashMap<Int, Int>()
        var i = 1
        while(i < n) {
            if (i > 0 && street[i - 1] == street[i]) {
                var j = i + 1
                var length = 2
                while (j < n && street[j - 1] == street[j]) {
                    j++
                    length++
                }
                map[street[i]] = map.getOrDefault(street[i], 0) + length
                i = j
            } else {
                i++
            }
        }
        val maxValue = if(map.isNotEmpty()) map.maxWith(kotlin.Comparator{k1, k2 -> map[k1.key]!!.compareTo(map[k2.key]!!)})!!.key else -1
        val max = if(map.isNotEmpty()) map[maxValue] else 1
        var ans = 0
        i = if(maxValue == -1) 1 else 0
        while (i < n) {
            if (street[i] == maxValue) {
                i++
            } else {
                ans++
                i += k
            }
        }
        println(ans)
    }
}


fun main() = output {
    repeat(ri()) {
        val (n, k) = ris(2)
        val arr = ria(n)
        val colors = arr.distinct()

        fun IntArray.days(c: Int, k: Int): Int {
            var days = 0
            var last = Int.MIN_VALUE
            for (i in 0 until size) {
                if (get(i) != c) {
                    if (last + k <= i) {
                        last = i
                        days++
                    }
                }
            }
            return days
        }

        println(colors.map { arr.days(it, k) }.min()!! )
    }
}

val INPUT: java.io.InputStream = System.`in` //

val OUTPUT: java.io.PrintStream = System.out //

fun output(block: java.io.PrintWriter.() -> Unit) {
	printWriter.block()
	printWriter.flush()
} //

val printWriter = java.io.PrintWriter(java.io.BufferedWriter(java.io.OutputStreamWriter(OUTPUT))) //

val inputReader = INPUT.bufferedReader() //

var inputTokenizer: java.util.StringTokenizer = java.util.StringTokenizer("") //

fun rs(): String {
	while (inputTokenizer.hasMoreTokens().not()) inputTokenizer = java.util.StringTokenizer(inputReader.readLine() ?: return "", " ")
	return inputTokenizer.nextToken()
} //

fun rss(n: Int) = List(n) { rs() } //

fun ri() = rs().toInt() //
fun ris() = rln().split(" ").map { it.toInt() } //
fun ris(n: Int) = List(n) { rs().toInt() } //
fun ria(n: Int) = IntArray(n) { rs().toInt() } //

fun rd() = rs().toDouble() //
fun rds() = rln().split(" ").map { it.toDouble() } //
fun rds(n: Int) = List(n) { rs().toDouble() } //
fun rda(n: Int) = DoubleArray(n) { rs().toDouble() } //

fun rl() = rs().toLong() //
fun rls() = rln().split(" ").map { it.toLong() } //
fun rls(n: Int) = List(n) { rs().toLong() } //
fun rla(n: Int) = LongArray(n) { rs().toLong() } //

fun rln() = inputReader.readLine()!! //
fun rlns(n: Int) = List(n) { rln() } //
fun rlnOrNull(): String? = inputReader.readLine() //

fun rc() = rs()[0] //
fun rca(): CharArray = rln().toCharArray() //


fun main() {
    repeat(readInt()) {
        val (n,k) = readInts()
        val c = readInts()
        val res = (1..100).minOf { rc ->
            var j = 0
            var r = 0
            while (j < c.size) {
                if (c[j] != rc) {
                    j += k
                    r ++
                } else {
                    j ++
                }
            }
            r
        }
        println(res)
    }
}
private val inp = System.`in`.bufferedReader()
private fun readLn() = inp.readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ").filter { !it.isBlank() }
private fun readLongs() = readStrings().map { it.toLong() }
private fun readInts() = readStrings().map { it.toInt() }


import java.io.*
import java.util.*
import kotlin.Comparator
import kotlin.collections.HashMap
import kotlin.collections.HashSet
import kotlin.system.measureTimeMillis

class Solution : Runnable {
    override fun run() {
        solve()
    }

    fun start() {
        Thread(null, Solution(), "whatever", (1 shl 27).toLong()).start()
    }
}

fun main(args: Array<String>) {
    Solution().start()
}

class IO {
    companion object {

        private val reader: InputReader
        private val writer: OutputWriter

        init {
            if (System.getProperty("ONLINE_JUDGE") == null) {
                reader = InputReader(FileInputStream("/Users/300041735/competitiveProgramming/src/codeforces/in.txt"))
                writer = OutputWriter(FileOutputStream("/Users/300041735/competitiveProgramming/src/codeforces/out.txt"))
            } else {
                reader = InputReader(System.`in`)
                writer = OutputWriter(System.`out`)
            }
        }

        private fun readMultipleInts(count: Int): List<Int> {
            val map = mutableListOf<Int>()
            repeat(count) {
                map.add(reader.readInt())
            }
            return map
        }

        fun readInt() = reader.readInt()
        fun readLong() = reader.readLong()
        fun readTwoInts() = readMultipleInts(2)
        fun readThreeInts() = readMultipleInts(3)
        fun readFourInts() = readMultipleInts(4)
        fun readFiveInts() = readMultipleInts(5)
        fun readSixInts() = readMultipleInts(6)
        fun readString() = reader.readString()
        fun readTree(n: Int): MutableMap<Int, MutableList<Int>> {
            val graph = mutableMapOf<Int, MutableList<Int>>()
            repeat(n - 1) {
                val u = reader.readInt()
                val v = reader.readInt()
                if (!graph.containsKey(u)) graph[u] = mutableListOf()
                if (!graph.containsKey(v)) graph[v] = mutableListOf()
                graph[u]!!.add(v)
                graph[v]!!.add(u)
            }
            return graph
        }

        fun readIntArray(n: Int): IntArray {
            return IntArray(n) { readInt() }
        }

        fun readLongArray(n: Int): Array<Long> {
            return Array(n) { readLong() }
        }

        fun write(obj: Any) {
            writer.printLine(obj)
        }

        fun flushOutput() {
            writer.flush()
        }

        fun closeOutput() {
            writer.close()
        }
    }
}

class MATH {
    companion object {

        val mod = 998244353
        var ispre = false

        val factMod = Array(300002) { 1 }

        fun pre() {
            for (i in 2 until 300001) {
                factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()
            }
        }

        fun gcd(a: Int, b: Int): Int {
            if (b == 0)
                return a
            return gcd(b, a % b)
        }

        fun gcd(a: Long, b: Long): Long {
            if (b == 0L)
                return a
            return gcd(b, a % b)
        }

        fun inverseMod(a: Int): Int {
            return powMod(a, mod - 2)
        }

        fun powMod(a: Int, b: Int): Int {
            //calculate a to the power b mod m
            if (b == 0) return 1
            return if (b % 2 == 1) {
                prodMod(a, powMod(a, b - 1))
            } else {
                val p = powMod(a, b / 2)
                prodMod(p, p)
            }
        }

        fun ncr(n: Int, r: Int): Int {
            if (!ispre) pre(); ispre = true
            return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()
        }

        fun prodMod(val1: Int, val2: Int): Int {
            return ((val1.toLong() * val2) % mod).toInt()
        }

    }
}

fun solve() {

    //val t = IO.readInt()
    val t =IO.readInt()
    repeat(t){
        val (n, k ) = IO.readTwoInts()
        val houses = IO.readIntArray(n)
        var min = Int.MAX_VALUE
        for (i in 1 until 101){
            //let's paint the houses with color i
            var j = 0
            var paints = 0
            while (j < n){
                if (houses[j] == i){
                    j++
                }else{
                    paints++
                    j+= k
                }
            }
            min = Math.min(min, paints)
        }
        IO.write(min)
    }

    IO.flushOutput()
    IO.closeOutput()
}

class SuffixArray(val input: String) {
    //time complexity is n(log(n))^2

    fun sa(): IntArray {
        val n = input.length
        var cur = IntArray(n) { i -> input[i] - 'a' } //will store the current sort order
        for (i in 1 until 20) {
            val newCur = IntArray(n) { 0 }
            val newlist = mutableListOf<Triple<Int, Int, Int>>()
            for (j in 0 until n) {
                newlist.add(Triple(j, cur[j], if (j + power(2, i) < n) cur[j + power(2, i)] else -1))
            }
            newlist.sortWith(comparator())
            //after sorting
            for (j in 0 until n) {
                newCur[newlist[j].first] = if (j > 0 && newlist[j].second == newlist[j - 1].second && newlist[j].third == newlist[j - 1].third) newCur[newlist[j - 1].first] else j
            }
            cur = newCur

        }
        return cur
    }

    internal class comparator : Comparator<Triple<Int, Int, Int>> {
        override fun compare(o1: Triple<Int, Int, Int>?, o2: Triple<Int, Int, Int>?): Int {
            if (o1!!.second != o2!!.second) {
                return o1.second.compareTo(o2.second)
            } else {
                //both are equal what to do now
                return o1.third.compareTo(o2.third)
            }
        }
    }
}

fun get32BitBinaryRepresentation(ll: Int): String {
    var l = ll
    val res = StringBuilder()
    while (l != 0) {
        if (l % 2 == 0) res.append('0') else res.append('1')
        l /= 2
    }
    while (res.length != 32) {
        res.append('0')
    }
    return res.toString().reversed()
}

fun getNum(s: String): Long {
    var ans = 0L
    //IO.write("ans : $s")
    for (i in 0 until 64) {
        ans = 2 * ans + (s[i] - '0')
    }
    return ans
}

class Primes {
    val limit = 3200
    val composites = IntArray(limit + 1) { 0 }
    val factors = IntArray(limit + 1) { 0 }
    val preFactors = IntArray(limit + 1) { 0 }
    val primes = mutableListOf<Int>()
    val memo = mutableMapOf<Int, MutableSet<Int>>()

    init {
        sieve()
    }

    fun sieve() {
        for (i in 2 until limit + 1) {
            if (composites[i] == 0) {
                primes.add(i)
                var cur = 1
                while (cur * i <= limit) {
                    composites[cur * i] = i
                    cur++
                }
            }
        }
    }

    fun calcFactors(n: Int): MutableSet<Int> {
        //we have all the primes till 1 lakh factorize the n
        if (memo.containsKey(n)) return memo[n]!!
        var num = n
        val factors = mutableSetOf<Int>()
        primes.forEach {
            while (num % it == 0) {
                factors.add(it)
                num = num / it
            }
        }
        if (num != 1) {
            factors.add(num)
        }
        memo[n] = factors
        return factors
    }
}

fun isBitSet(num: Int, i: Int): Boolean {
    return (num.and(1.shl(i)) > 0)
}

fun power(i: Int, j: Int): Int {
    if (j == 0) return 1
    return i * power(i, j - 1)
}

class MinSegmentTree(
        input: IntArray
) {
    private val tree: Array<Int>
    private val lazy: Array<Int>

    constructor(size: Int) : this(IntArray(size) { Int.MAX_VALUE })

    init {
        val size = nextPowerOfTwo(input.size)
        tree = Array(2 * size) { Int.MAX_VALUE }
        lazy = Array(2 * size) { Int.MAX_VALUE }
        for (i in 0 until input.size) {
            tree[i + size] = input[i]
        }
        for (i in (size - 1) downTo 1) {
            tree[i] = Math.min(tree[leftChild(i)], tree[rightChild(i)])
        }
    }

    private fun updateTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int, value: Int) {
        //updateLazyNode(index, lowerBound, upperBound, lazy[index])
        if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return
        else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) updateLazyNode(index, lowerBound, upperBound, value)
        else {
            updateTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index), value)
            updateTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index), value)
            tree[index] = Math.min(tree[leftChild(index)], tree[rightChild(index)])
        }
    }

    private fun queryTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int): Int {
        //updateLazyNode(index, lowerBound, upperBound, lazy[index])
        if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return Int.MAX_VALUE
        else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) return tree[index]
        else {
            return Math.min(queryTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index)),
                    queryTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index)))
        }
    }

    private fun updateLazyNode(index: Int, lowerBound: Int, upperBound: Int, delta: Int) {
        tree[index] += delta
        if (lowerBound != upperBound) {
            lazy[leftChild(index)] += delta
            lazy[rightChild(index)] += delta
        }
        lazy[index] = 0
    }

    fun getElements(N: Int): List<Int> {
        return tree.copyOfRange(tree.size / 2, tree.size / 2 + N).asList()
    }

    fun update(lowerRange: Int, upperRange: Int, value: Int) {
        updateTree(lowerRange, upperRange, 1, lazy.size / 2, 1, value)
    }

    fun query(lowerRange: Int, upperRange: Int): Int {
        return queryTree(lowerRange, upperRange, 1, lazy.size / 2, 1)
    }

    private fun noOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb > u || ub < l)

    private fun completeOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb >= l && ub <= u)

    private fun nextPowerOfTwo(num: Int): Int {
        var exponent = 2
        while (true) {
            if (exponent >= num) {
                return exponent
            }
            exponent *= 2
        }
    }

    private fun midIndex(l: Int, r: Int) = (l + r) / 2
    private fun parent(i: Int) = i / 2
    private fun leftChild(i: Int) = 2 * i
    private fun rightChild(i: Int) = 2 * i + 1

}

class InputReader(private val stream: InputStream) {
    private val buf = ByteArray(1024)
    private var curChar: Int = 0
    private var numChars: Int = 0
    private val filter: SpaceCharFilter? = null

    fun read(): Int {
        if (numChars == -1)
            throw InputMismatchException()
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = stream.read(buf)
            } catch (e: IOException) {
                throw InputMismatchException()
            }

            if (numChars <= 0)
                return -1
        }
        return buf[curChar++].toInt()
    }

    fun readInt(): Int {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        var sgn = 1
        if (c == '-'.toInt()) {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0'.toInt() || c > '9'.toInt())
                throw InputMismatchException()
            res *= 10
            res += c - '0'.toInt()
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun readLong(): Long {
        var c = read()
        while (isSpaceChar(c)) {
            c = read()
        }
        var sgn: Long = 1
        if (c == '-'.toInt()) {
            sgn = -1
            c = read()
        }
        var number: Long = 0
        do {
            number *= 10L
            number += (c - '0'.toInt()).toLong()
            c = read()
        } while (!isSpaceChar(c))
        return number * sgn
    }

    fun readString(): String {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        val res = StringBuilder()
        do {
            res.appendCodePoint(c)
            c = read()
        } while (!isSpaceChar(c))
        return res.toString()
    }

    fun isSpaceChar(c: Int): Boolean {
        return filter?.isSpaceChar(c)
                ?: (c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1)
    }

    operator fun next(): String {
        return readString()
    }

    interface SpaceCharFilter {
        fun isSpaceChar(ch: Int): Boolean
    }
}

class OutputWriter {
    private val writer: PrintWriter

    constructor(outputStream: OutputStream) {
        writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))
    }

    constructor(writer: Writer) {
        this.writer = PrintWriter(writer)
    }

    fun print(vararg objects: Any) {
        for (i in objects.indices) {
            if (i != 0)
                writer.print(' ')
            writer.print(objects[i])
        }
    }

    fun printLine(vararg objects: Any) {
        print(*objects)
        writer.println()
    }

    fun close() {
        writer.close()
    }

    fun flush() {
        writer.flush()
    }

}

class DinitzMaxFlowSolver(val n: Int, val s: Int, val t: Int, val graph: MutableMap<Int, MutableList<Edge>>, val edgeMap: MutableMap<Pair<Int, Int>, Edge>) {

    private val level = IntArray(n + 1) { -1 }  //storing levels of each vertex in level graph
    var maxFlow = 0L

    init {
        solve()
    }

    fun solve() {
        val next = IntArray(n + 1) { 0 }
        while (bfs()) {
            Arrays.fill(next, 0)
            var flow = 0L
            do {
                maxFlow += flow
                flow = dfs(s, next, Long.MAX_VALUE)
            } while (flow != 0L)
        }
    }

    private fun dfs(at: Int, next: IntArray, flow: Long): Long {
        if (at == t) return flow
        var size = 0
        if (graph.containsKey(at)) size = graph[at]!!.size
        while (next[at] < size) {
            val edge = graph[at]!!.get(next[at])
            if (edge.remainingCapacity() > 0 && level[edge.to] == level[at] + 1) {
                val bottleNeck = dfs(edge.to, next, Math.min(flow, edge.remainingCapacity()))
                if (bottleNeck > 0) {
                    edgeMap[Pair(edge.from, edge.to)]!!.flow += bottleNeck
                    edgeMap[Pair(edge.to, edge.from)]!!.flow -= bottleNeck
                    return bottleNeck
                }
            }
            next[at]++
        }
        return 0
    }

    private fun bfs(): Boolean {
        Arrays.fill(level, -1)
        val curLevel = ArrayDeque<Int>()
        curLevel.add(s)
        level[s] = 0

        while (curLevel.isNotEmpty()) {
            val top = curLevel.poll()
            if (graph.containsKey(top)) {
                graph[top]!!.forEach {
                    if (it.remainingCapacity() > 0 && level[it.to] == -1) {
                        level[it.to] = level[top] + 1
                        curLevel.offer(it.to)
                    }
                }
            }
        }
        return level[t] != -1
    }

}

class Edge(val from: Int, val to: Int, val capacity: Long) {
    var flow = 0L
    fun remainingCapacity(): Long {
        return capacity - flow
    }
}

class ConnectedComponents(val g: Graph, val price: IntArray) {

    private val visited = HashSet<Int>()
    private val stack = Stack<Int>()
    private val revertedGraph = revertGraph()
    private val component = mutableListOf<Int>()
    var ways = 1L
    var min = 0L
    val mod = 1000000007

    init {
        getConnectedComponents()
    }

    fun getConnectedComponents() {
        g.vertices.forEach {
            if (!visited.contains(it)) {
                visited.add(it)
                dfs(it)
            }
        }

        visited.clear()
        while (stack.isNotEmpty()) {
            val node = stack.pop()
            if (!visited.contains(node)) {
                visited.add(node)
                dfs2(node)
                var take = Int.MAX_VALUE
                for (i in 0 until component.size) {
                    if (price[component[i] - 1] < take) {
                        take = price[component[i] - 1]
                    }
                }
                min += take
                ways = (ways * component.filter { price[it - 1] == take }.count()) % mod
                component.clear()
            }
        }
    }

    fun dfs(node: Int) {
        if (g.edges.containsKey(node)) {
            g.edges[node]!!.forEach {
                if (!visited.contains(it)) {
                    visited.add(it)
                    dfs(it)
                }
            }
        }
        stack.push(node)
    }

    fun dfs2(node: Int) {
        component.add(node)
        if (revertedGraph.edges.containsKey(node)) {
            revertedGraph.edges[node]!!.forEach {
                if (!visited.contains(it)) {
                    visited.add(it)
                    dfs2(it)
                }
            }
        }
    }

    fun revertGraph(): Graph {
        val newEdges = mutableMapOf<Int, MutableList<Int>>()
        g.edges.forEach {
            val u = it.key
            val vs = it.value
            vs.forEach { v ->
                if (!newEdges.containsKey(v)) {
                    newEdges[v] = mutableListOf()
                }
                newEdges[v]!!.add(u)
            }
        }
        return Graph(g.vertices, newEdges)
    }
}

data class Graph(val vertices: MutableList<Int>, val edges: MutableMap<Int, MutableList<Int>>)


fun main(){
    val q = readLine()!!.toInt()

    for (i in 1..q){
        val (n, k) = readLine()!!.split(" ").map { it.toInt() }
        val a = readLine()!!.split(" ").map { it.toInt() }
        val p = a.max()
        val colors = IntArray(p!!)
        val currents = IntArray(p)
        val starts = BooleanArray(p)

        for (c1 in 1..p){
            for (j in a){
                if (currents[c1-1]==k){
                    colors[c1-1]++
                    currents[c1-1]=0
                    starts[c1-1]=false
                }
                if (starts[c1-1]){
                    currents[c1-1]++
                }else if (j!=c1){
                    starts[c1-1]=true
                    currents[c1-1]=1
                }
            }
            if (currents[c1-1]>0){
                colors[c1-1]++
            }

        }
        println(colors.min())
    }
}


fun main(){
    val q = readLine()!!.toInt()

    for (i in 1..q){
        val (n, k) = readLine()!!.split(" ").map { it.toInt() }
        val a = readLine()!!.split(" ").map { it.toInt() }
        val b = a.sorted()
        var color = 0
        var last = 0
        var max = 0
        var sz = 0
        for (j in b){
            if (j==last){
                sz++
            }else{
                if (sz>=max){
                    color = last
                    max = sz
                    sz = 1
                }
                last = j
            }
        }
        if (sz>max){
            color = last
        }
        var sum = 0
        var current = 0
        var start = false
        for (j in a){
            if (current==k){
                sum++
                current = 0
                start = false
            }
            if (start){
                current++
            }else if (j!=color){
                start=true
                current = 1
            }
        }
        if (current>0){
            sum++
        }
        println(sum)
    }
}


import java.lang.Math.abs
import java.util.*
import java.util.function.BiFunction
import kotlin.math.min

fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    val t = nextInt()
//    val t = 1
    repeat(t) {
        val n = nextInt()
        val k = nextInt()
        val l = (0 until n).map { nextInt() }
        fun solve(c: Int): Int {
            var r = 0
            var i = 0
            while (true) {
                while (i < l.size && l[i] == c) {
                    i++
                }
                if (i >= l.size) {
                    break
                }
                i += k
                r++
            }
            return r
        }
        println((1..100).map { solve(it) }.min()!!)

    }
}


import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main() {
    val r = FastReader()
    val t = r.nextInt()
    repeat(t) {
        val (n, k) = r.nextIntArr(2)
        val c = r.nextIntArr(n)
        val a = Array(100) { Value(0, 0) }
        for (i in 0 until n) {
            for (color in 0 until 100) {
                val x = a[color]
                if (x.left > 0)
                    x.left--
                else if (color+1 != c[i]) {
                    x.days++
                    x.left = k - 1
                }
            }
        }
        println(a.minOf { it.days })
    }
}

data class Value(
    var days: Int,
    var left: Int
)

@Suppress("MemberVisibilityCanBePrivate")
internal class FastReader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    private var tokenizer: StringTokenizer? = null

    operator fun next(): String {
        var t = tokenizer
        while (t == null || !t.hasMoreElements())
            t = StringTokenizer(br.readLine())
        tokenizer = t
        return t.nextToken()
    }

    fun nextInt() = next().toInt()

    fun nextLong(): Long = next().toLong()

    fun nextDouble(): Double = next().toDouble()

    fun nextLine(): String = br.readLine()

    fun nextIntArr(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextDoubleArr(n: Int): DoubleArray = DoubleArray(n) { nextDouble() }

    fun nextLongArr(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextIntArr2(n: Int, m: Int): Array<IntArray> = Array(n) { IntArray(m) { nextInt() } }

    fun nextLongArr2(n: Int, m: Int): Array<LongArray> = Array(n) { LongArray(m) { nextLong() } }
}


import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main() {
    val r = FastReader()
    val t = r.nextInt()
    repeat(t) {
        val (n, k) = r.nextIntArr(2)
        val c = r.nextIntArr(n)
        val a = Array(100) { Value(0, 0) }
        for (i in 0 until n) {
            for (color in 0 until 100) {
                val x = a[color]
                if (x.left > 0)
                    x.left--
                else if (color != c[i]) {
                    x.days++
                    x.left = k - 1
                }
            }
        }
        println(a.minOf { it.days })
    }
}

data class Value(
    var days: Int,
    var left: Int
)

@Suppress("MemberVisibilityCanBePrivate")
internal class FastReader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    private var tokenizer: StringTokenizer? = null

    operator fun next(): String {
        var t = tokenizer
        while (t == null || !t.hasMoreElements())
            t = StringTokenizer(br.readLine())
        tokenizer = t
        return t.nextToken()
    }

    fun nextInt() = next().toInt()

    fun nextLong(): Long = next().toLong()

    fun nextDouble(): Double = next().toDouble()

    fun nextLine(): String = br.readLine()

    fun nextIntArr(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextDoubleArr(n: Int): DoubleArray = DoubleArray(n) { nextDouble() }

    fun nextLongArr(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextIntArr2(n: Int, m: Int): Array<IntArray> = Array(n) { IntArray(m) { nextInt() } }

    fun nextLongArr2(n: Int, m: Int): Array<LongArray> = Array(n) { LongArray(m) { nextLong() } }
}


fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(' ').map { it.toInt() }

fun main() {
    repeat(readInt()) {
        val (n, k) = readInts()
        val vs = readInts()
        val cols = vs.toSet()
        val cost = cols.map { paint(vs, k, it) }.min()
        println(cost)
    }
}

fun paint(vs: List<Int>, k: Int, c: Int): Int {
    var i = 0
    var cost = 0
    while (i < vs.size) {
        if (vs[i] == c) {
            i++
        } else {
            i += k
            cost++
        }
    }
    return cost
}


import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesInSubtree[];
    static int k;
    static class Graph {
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        boolean visited[];

        public Graph(int V) {
            this.V = V;
            adj = new ArrayList<>(V);
            //pq = new PriorityQueue<>(V, new edge(-1, -1));
            nodesInSubtree = new int[V];
            dist = new int[V];
            visited = new boolean[V];

            for (int i = 0; i < V; i++) {
                dist[i] = Integer.MAX_VALUE;
                adj.add(i, new ArrayList<>());

            }
        }

        void addedge(int u, int v, int w) {
            adj.get(u).add(new edge(v, w));
            adj.get(v).add(new edge(u, w));
        }

        void rDfs(int src, int e) {
            int m = k;
            nodesInSubtree[src] = 1;
            int sz = adj.get(src).size();
            int nodes[] = new int[sz];
            for (int i = 0; i < adj.get(src).size(); i++) {
                if (adj.get(src).get(i).dest == e) {
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodes[i] = nodesInSubtree[adj.get(src).get(i).dest];
            }

            if(sz<m){
                return;
            }else if(sz<=m && src != 1){
               return;
            }

            Arrays.sort(nodes);

            for(int i = sz - 1; i>=0 && m>0; i--,m--){
                nodesInSubtree[src] += nodes[i];
            }

        }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */
    }

    static  int I[];
    static  int  L[];
    static int LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }

        int lisLength = 1;

        int cm = 0;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }

            if(I[high]==arr[i]){
                cm++;
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
        return 1;
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

    public static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];
    static int smallestFactor[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        smallestFactor = new int[n+1];

        smallestFactor[1] = 1;
        for(int i=2;i<n;i++) {
            prime[i] = true;
            smallestFactor[i] = i;
        }

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                smallestFactor[p] = p;
                for(int i = p*p; i <= n; i += p) {
                    prime[i] = false;
                    smallestFactor[i] = min(p,smallestFactor[i]);
                }
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static int sumOfDigits(int n){
        int digitSum = 0;
        while (n>0){
            digitSum+=n%10;
            n/=10;
        }
        return digitSum;
    }

    static boolean checkSum(PriorityQueue<Integer> pq, long s){
        long sum = 0;
        while (!pq.isEmpty()){
            sum+= pq.poll();
        }
        if(sum>s){
            return false;
        }

        return true;

    }

    static int dsu[];

    static int findParent(int x){
        if(dsu[x]<0){
            return x;
        }
        return findParent(dsu[x]);
    }

    static class Primes implements Comparable<Primes>{
        int prime;
        int occurance;

        @Override
        public int compareTo(Primes o) {
            return this.occurance - o.occurance;
        }
    }

    static long convertToDecimal(String s){
        if(s.charAt(0)=='0'){
            if(s.charAt(1)=='x'){
                String res = s.substring(2,s.length());
                return Long.parseLong(res,16);
            }else{
                String res = s.substring(1,s.length());
                return Long.parseLong(s,8);
            }
        }
        return Long.parseLong(s);
    }

    public static void main(String[] args) {

        int testcase = sc.nextInt();
        int z = 0;
        while (z++<testcase){
            int n = sc.nextInt();
            int k = sc.nextInt();
            int c[] = new int[n];
            int colors[] = new int[101];
            for(int i = 0; i<n; i++){
                c[i] = sc.nextInt();
                colors[c[i]]++;
            }

            int ans = Integer.MAX_VALUE;

            for(int i = 0; i<=100; i++){
                if(colors[i]>0){
                    int res = 0;
                    int cnt = 0;
                    for(int j =0; j<n; j++){
                        if(c[j]!=i){
                            cnt++;
                        }else{
                            res += (int)ceil((double)cnt/k);
                            cnt =0;
                        }
                    }
                    res += (int)ceil((double)cnt/k);
                    ans = min(ans,res);
                }
            }

            pw.println(ans);

        }

        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesInSubtree[];
    static int k;
    static class Graph {
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;
        boolean visited[];

        public Graph(int V) {
            this.V = V;
            adj = new ArrayList<>(V);
            //pq = new PriorityQueue<>(V, new edge(-1, -1));
            nodesInSubtree = new int[V];
            dist = new int[V];
            visited = new boolean[V];

            for (int i = 0; i < V; i++) {
                dist[i] = Integer.MAX_VALUE;
                adj.add(i, new ArrayList<>());

            }
        }

        void addedge(int u, int v, int w) {
            adj.get(u).add(new edge(v, w));
            adj.get(v).add(new edge(u, w));
        }

        void rDfs(int src, int e) {
            int m = k;
            nodesInSubtree[src] = 1;
            int sz = adj.get(src).size();
            int nodes[] = new int[sz];
            for (int i = 0; i < adj.get(src).size(); i++) {
                if (adj.get(src).get(i).dest == e) {
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodes[i] = nodesInSubtree[adj.get(src).get(i).dest];
            }

            if(sz<m){
                return;
            }else if(sz<=m && src != 1){
                return;
            }

            Arrays.sort(nodes);

            for(int i = sz - 1; i>=0 && m>0; i--,m--){
                nodesInSubtree[src] += nodes[i];
            }

        }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */
    }

    static  int I[];
    static  int  L[];
    static int LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }

        int lisLength = 1;

        int cm = 0;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }

            if(I[high]==arr[i]){
                cm++;
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
        return 1;
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

    public static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];
    static int smallestFactor[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        smallestFactor = new int[n+1];

        smallestFactor[1] = 1;
        for(int i=2;i<n;i++) {
            prime[i] = true;
            smallestFactor[i] = i;
        }

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                smallestFactor[p] = p;
                for(int i = p*p; i <= n; i += p) {
                    prime[i] = false;
                    smallestFactor[i] = min(p,smallestFactor[i]);
                }
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static int sumOfDigits(int n){
        int digitSum = 0;
        while (n>0){
            digitSum+=n%10;
            n/=10;
        }
        return digitSum;
    }

    static boolean checkSum(PriorityQueue<Integer> pq, long s){
        long sum = 0;
        while (!pq.isEmpty()){
            sum+= pq.poll();
        }
        if(sum>s){
            return false;
        }

        return true;

    }

    static int dsu[];

    static int findParent(int x){
        if(dsu[x]<0){
            return x;
        }
        return findParent(dsu[x]);
    }

    static class Primes implements Comparable<Primes>{
        int prime;
        int occurance;

        @Override
        public int compareTo(Primes o) {
            return this.occurance - o.occurance;
        }
    }

    static long convertToDecimal(String s){
        if(s.charAt(0)=='0'){
            if(s.charAt(1)=='x'){
                String res = s.substring(2,s.length());
                return Long.parseLong(res,16);
            }else{
                String res = s.substring(1,s.length());
                return Long.parseLong(s,8);
            }
        }
        return Long.parseLong(s);
    }

    public static void main(String[] args) {

        int testcase = sc.nextInt();
        int z = 0;
        while (z++<testcase){
            int n = sc.nextInt();
            int k = sc.nextInt();
            int c[] = new int[n];
            int colors[] = new int[101];
            for(int i = 0; i<n; i++){
                c[i] = sc.nextInt();
                colors[c[i]]++;
            }

            int ans = Integer.MAX_VALUE;

            for(int i = 0; i<=100; i++){
                if(colors[i]>0){
                    int res = 0;

                    for(int j =0; j<n; j++){
                        if(c[j]!=i){
                            res++;
                            j+=k-1;
                        }
                    }
                    ans = min(ans,res);
                }
            }

            pw.println(ans);

        }

        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.Scanner;

public class B {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new BufferedInputStream(System.in, 1 << 20));

        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] cs = new int[n];
            for (int j = 0; j < n; j++) {
                cs[j] = in.nextInt();
            }
            int[] marks = new int[101];
            int[] counts = new int[101];
            for (int j = 0; j <= 100; j++) {
                marks[j] = -1;
                counts[j] = 0;
            }
            for (int j = 0; j < n; j++) {
                int c = cs[j];
                if (marks[c] >= j - 1) {
                    marks[c] = Math.max(marks[c], j);
                } else {
                    int days = ((j - marks[c] - 2) / k) + 1;
                    counts[c] += days;
                    marks[c] = Math.max(marks[c] + k * days, j);
                }
            }
            for (int j = 1; j <= 100; j++) {
                if (marks[j] <  n - 1) {
                    counts[j] += (n - 2 - marks[j]) / k + 1;
                }
            }
            int min = counts[1];
            for (int j = 1; j <= 100; j++) {
                min = Math.min(min, counts[j]);

            }
            System.out.println(min);
        }
    }
}


import java.util.*;

public class dynamicprogramming{

  public static void main(String[]args){

           Scanner sc=new Scanner(System.in);

           int t=sc.nextInt();

           for(int l=0;l<t;l++){

                int n=sc.nextInt();

                int c=sc.nextInt();

                int[]arr=new int[n];

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

            	   arr[i]=sc.nextInt();

               }

          int val=0;

          int count=0;

          int h=0;

          int ans=Integer.MAX_VALUE;

          boolean[]r=new boolean[101];

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

    	 count=0;
    	 val=arr[j];
    	 h=0;
    	 if(r[arr[j]]==true){

    	     continue;

    	 }else{

    	    r[arr[j]]=true;

    	 }

          while(h<n){

             while(h<n&&arr[h]==val){

                  h++;

             }
            if(h>n-1){

               break;

            }
            h+=c;
            count++;

          }

          ans=Math.min(ans,count);

     }

          System.out.println(ans);

           }
  }

}


import java.util.*;

public class dynamicprogramming{

  public static void main(String[]args){

           Scanner sc=new Scanner(System.in);

           int t=sc.nextInt();

           for(int l=0;l<t;l++){

                int n=sc.nextInt();

                int c=sc.nextInt();

                int[]arr=new int[n];

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

            	   arr[i]=sc.nextInt();

               }

          int val=0;

          int count=0;

          int h=0;

          int ans=Integer.MAX_VALUE;

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

    	 count=0;
    	 val=arr[j];

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

           if(h==0){

              if(arr[i]!=val){

                  count++;

                  h=c-1;

              }

           }else{

               if(arr[i]!=val){

//            	   System.out.println("lo");

                   h--;

               }else{

                  h=0;
//                  System.out.println("jo");

               }

           }

          }

        ans=Math.min(count, ans);

     }

          System.out.println(ans);

           }
  }

}


import java.util.*;

import java.util.*;

public class dynamicprogramming{

  public static void main(String[]args){

           Scanner sc=new Scanner(System.in);

           int t=sc.nextInt();

           for(int l=0;l<t;l++){

                int n=sc.nextInt();

                int c=sc.nextInt();

                int[]arr=new int[n];

                int[]a=new int[101];

              int f=Integer.MIN_VALUE;
              int val=0;

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

                  arr[i]=sc.nextInt();

                  a[arr[i]]++;

               if(f<a[arr[i]]){

                    val=arr[i];

                    f=a[arr[i]];

               }

          }

          int count=0;

          int h=0;

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

           if(h==0){

              if(arr[i]!=val){

                  count++;

                  h=c-1;

              }

           }else{

               if(arr[i]!=val){

                   h--;

               }else{

                  h=0;

               }

           }

          }

          System.out.println(count);

           }
  }

}


import java.util.*;

public class dynamicprogramming{

  public static void main(String[]args){

           Scanner sc=new Scanner(System.in);

           int t=sc.nextInt();

           for(int l=0;l<t;l++){

                int n=sc.nextInt();

                int c=sc.nextInt();

                int[]arr=new int[n];

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

            	   arr[i]=sc.nextInt();

               }

          int val=0;

          int count=0;

          int h=0;

          int ans=Integer.MAX_VALUE;

          boolean[]r=new boolean[101];

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

    	 count=0;
    	 val=arr[j];
    	 h=0;

      if(r[arr[j]]==true){

               continue;
      }else{

    	 r[arr[j]]=true;

      }

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

           if(h==0){

              if(arr[i]!=val){

                  count++;

                  h=c-1;

              }

           }else{

               if(arr[i]!=val){

//            	   System.out.println("lo");

                   h--;

               }else{

                  h=0;
//                  System.out.println("jo");

               }

           }

          }

        ans=Math.min(count, ans);

     }

          System.out.println(ans);

           }
  }

}


//package ex2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) {
        int t = FastScanner.nextInt();
        for (int j = 0; j < t; j++) {
            int n = FastScanner.nextInt();
            int k = FastScanner.nextInt();
            int[] c = new int[n];
            for (int i = 0; i < n; i++) {
                c[i] = FastScanner.nextInt();
            }

            HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
            for (int i = 0; i < c.length; i++) {
                hm.put(c[i], i);
            }

            int countMin = Integer.MAX_VALUE;
            int diff = diffValues(c);
            Integer[] diffV = hm.keySet().toArray(new Integer[0]);

            for (int i = 0; i < diff; i++) {
                int ind = 0;
                int count = 0;
                while(ind < n){
                    if(c[ind] != diffV[i]){
                        ind += k;
                        count++;
                    }
                    else{
                        ind++;
                    }
                }
                countMin = Math.min(countMin,count);
            }
            System.out.println(countMin == Integer.MAX_VALUE ? 0 : countMin);
        }
    }

    public static int getPopularElement(int[] a)
    {
        int count = 1, tempCount;
        int popular = a[0];
        int temp = 0;
        for (int i = 0; i < (a.length - 1); i++)
        {
            temp = a[i];
            tempCount = 0;
            for (int j = 1; j < a.length; j++)
            {
                if (temp == a[j])
                    tempCount++;
            }
            if (tempCount > count)
            {
                popular = temp;
                count = tempCount;
            }
        }
        return popular;
    }

    public static int diffValues(int[] numArray){
        int numOfDifferentVals = 0;

        ArrayList<Integer> diffNum = new ArrayList<Integer>();

        for(int i=0; i<numArray.length; i++){
            if(!diffNum.contains(numArray[i])){
                diffNum.add(numArray[i]);
            }
        }

        if(diffNum.size()==1){
            numOfDifferentVals = 0;
        }
        else{
            numOfDifferentVals = diffNum.size();
        }

        return numOfDifferentVals;
    }
}

class FastScanner {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer st = new StringTokenizer("");

    public static String next(){
        while (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {}
        }
        return st.nextToken();
    }

    public static String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {}
        return "";
    }

    public static char nextChar(){
        return next().charAt(0);
    }

    public static int nextInt(){
        return Integer.parseInt(next());
    }

    public static long nextLong(){
        return Long.parseLong(next());
    }

    public static double nextDouble(){
        return Double.parseDouble(next());
    }
}


//package ex2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) {
        int t = FastScanner.nextInt();
        for (int j = 0; j < t; j++) {
            int n = FastScanner.nextInt();
            int k = FastScanner.nextInt();
            int[] c = new int[n];
            for (int i = 0; i < n; i++) {
                c[i] = FastScanner.nextInt();
            }

            int pop = getPopularElement(c);

            int ind = 0;
            int count = 0;
            while(ind < n){
                if(c[ind] != pop){
                    ind += k;
                    count++;
                }
                else{
                    ind++;
                }
            }
            System.out.println(count);
        }
    }

    public static int getPopularElement(int[] a)
    {
        int count = 1, tempCount;
        int popular = a[0];
        int temp = 0;
        for (int i = 0; i < (a.length - 1); i++)
        {
            temp = a[i];
            tempCount = 0;
            for (int j = 1; j < a.length; j++)
            {
                if (temp == a[j])
                    tempCount++;
            }
            if (tempCount > count)
            {
                popular = temp;
                count = tempCount;
            }
        }
        return popular;
    }
}

class FastScanner {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer st = new StringTokenizer("");

    public static String next(){
        while (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {}
        }
        return st.nextToken();
    }

    public static String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {}
        return "";
    }

    public static char nextChar(){
        return next().charAt(0);
    }

    public static int nextInt(){
        return Integer.parseInt(next());
    }

    public static long nextLong(){
        return Long.parseLong(next());
    }

    public static double nextDouble(){
        return Double.parseDouble(next());
    }
}


//package ex2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) {
        int t = FastScanner.nextInt();
        for (int j = 0; j < t; j++) {
            int n = FastScanner.nextInt();
            int k = FastScanner.nextInt();
            int[] c = new int[n];
            for (int i = 0; i < n; i++) {
                c[i] = FastScanner.nextInt();
            }

            HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
            for (int i = 0; i < c.length; i++) {
                hm.put(c[i], i);
            }

            int countMin = Integer.MAX_VALUE;
            int diff = diffValues(c);
            Integer[] diffV = hm.keySet().toArray(new Integer[0]);

            for (int i = 0; i < diff; i++) {
                int ind = 0;
                int count = 0;
                while(ind < n){
                    if(c[ind] != diffV[i]){
                        ind += k;
                        count++;
                    }
                    else{
                        ind++;
                    }
                }
                countMin = Math.min(countMin,count);
            }
            System.out.println(countMin);
        }
    }

    public static int getPopularElement(int[] a)
    {
        int count = 1, tempCount;
        int popular = a[0];
        int temp = 0;
        for (int i = 0; i < (a.length - 1); i++)
        {
            temp = a[i];
            tempCount = 0;
            for (int j = 1; j < a.length; j++)
            {
                if (temp == a[j])
                    tempCount++;
            }
            if (tempCount > count)
            {
                popular = temp;
                count = tempCount;
            }
        }
        return popular;
    }

    public static int diffValues(int[] numArray){
        int numOfDifferentVals = 0;

        ArrayList<Integer> diffNum = new ArrayList<Integer>();

        for(int i=0; i<numArray.length; i++){
            if(!diffNum.contains(numArray[i])){
                diffNum.add(numArray[i]);
            }
        }

        if(diffNum.size()==1){
            numOfDifferentVals = 0;
        }
        else{
            numOfDifferentVals = diffNum.size();
        }

        return numOfDifferentVals;
    }
}

class FastScanner {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer st = new StringTokenizer("");

    public static String next(){
        while (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {}
        }
        return st.nextToken();
    }

    public static String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {}
        return "";
    }

    public static char nextChar(){
        return next().charAt(0);
    }

    public static int nextInt(){
        return Integer.parseInt(next());
    }

    public static long nextLong(){
        return Long.parseLong(next());
    }

    public static double nextDouble(){
        return Double.parseDouble(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner();
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = sc.nextInt();

			int ans = 1000000000;
			for (int i = 1; i <= 100; i++) {
				int cnt = 0;
				for (int j = 0; j < n; j++) {
					if (a[j] == i)
						continue;
					cnt++;
					j += k - 1;
				}
				ans = Math.min(ans, cnt);

			}
			System.out.println(ans);

		}

	}

	static boolean isValid(int n, int m, int i, int j) {
		return i >= 0 && i < n && j >= 0 && j < m;

	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public int subarraysDivByK(int[] A, int K) {
		int n = A.length;
		int ans[] = new int[n];

		for (int i = 0; i < n; i++) {
			ans[i] = (A[i] % K + K) % K;
		}
		for (int i = 1; i < n; i++) {
			ans[i] += ans[i - 1];

		}
		int c = 0;
		for (int i = 0; i < ans.length; i++) {
			if (ans[i] == 0)
				c++;
		}
		return c * (c + 1) / 2;

	}

}

class Scanner {
	BufferedReader br;
	StringTokenizer st;

	Scanner() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	String next() throws IOException {
		while (st == null || !st.hasMoreElements())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(next());
	}
}

//creating a hash table
//Hashtable<Integer, String> h = new Hashtable<Integer, String>();
//
//Hashtable<Integer, String> h1 = new Hashtable<Integer, String>();
//
//h.put(3, "Geeks");
//h.put(2, "forGeeks");
//h.put(1, "isBest");
//System.out.println(h.get(1));
//if (h.containsKey(1)) {
//	System.out.println(1111111);
//}
//if (h.containsValue("isBest")) {
//	System.out.println(1111111);
//}
//
//// create a clone or shallow copy of hash table h
//h1 = (Hashtable<Integer, String>) h.clone();
//
//// checking clone h1
////System.out.println("values in clone: " + h1);
//
//// clear hash table h
//h.clear();

//Creating object of the
// class linked list
//LinkedList<String> ll
//    = new LinkedList<String>();
//
//// Adding elements to the linked list
//ll.add("A");
//ll.add("B");
//ll.addLast("C");
//ll.addFirst("D");
//ll.add(2, "E");
//
//System.out.println(ll);
//
//ll.remove("B");
//ll.remove(3);
//ll.removeFirst();
//ll.removeLast();
//
//System.out.println(ll);

//Set<Integer> set = new HashSet<Integer>();
//try {
//   for(int i = 0; i < 5; i++) {
//      set.add(count[i]);
//   }
//   System.out.println(set);
//
//   TreeSet sortedSet = new TreeSet<Integer>(set);
//   System.out.println("The sorted list is:");
//   System.out.println(sortedSet);
//
//   System.out.println("The First element of the set is: "+ (Integer)sortedSet.first());
//   System.out.println("The last element of the set is: "+ (Integer)sortedSet.last());
//}
//catch(Exception e) {}


import java.util.Scanner;

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */

public class Main {
   public static void main(String[] args) {
      // Write your solution here
      Scanner scanner = new Scanner(System.in);
      int t = Integer.parseInt(scanner.nextLine());
      while (t-- > 0) {
         int n = scanner.nextInt();
         int k = scanner.nextInt();
         int[] arr = new int[n];
         for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
         }
         int max = Integer.MAX_VALUE;
         for (int i = 1; i <= 100; i++) {
            max = Math.min(max,make(arr,i,k));
         }
         System.out.println(max);
      }
   }

   private static int make(int[] arr, int color,int k) {
      int count = 0;
      int i = 0,n = arr.length;
      while (i < n){
         while (i < n && arr[i] == color){
            i++;
         }
         if(i < n) count++;
         i += k;
      }
      return count;
   }
}


import java.util.*;
public class rc{
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
		    int n=sc.nextInt(),k=sc.nextInt();
		    int a[]=new int[n],i=0;
		    Map<Integer,Integer> map = new HashMap<>();
		    while(i<n)
		        a[i++]=sc.nextInt();
		    for(i=0; i<n; i++){
		        if(!map.containsKey(a[i]))
		           map.put(a[i],1);
		        else
		           map.put(a[i],map.get(a[i])+1);
		    }
		    List<Map.Entry<Integer,Integer>> list = new ArrayList<>(map.entrySet());
		    Collections.sort(list,(p,q) -> p.getValue()-q.getValue());
		    int max = list.get(list.size()-1).getKey();
		    int cnt=0,days=0;
		    for(i=0; i<n; i++){
		        if(a[i]!=max)
		           cnt++;
		        else if(cnt>0){
		           days++;
		           cnt=0;
		        }
		        if(cnt==k){
		           days++;
		           cnt=0;
		        }
		    }
		    if(cnt>0)
		       days++;
		    System.out.println(days);
		}
	}
}


import java.util.*;
public class rc{
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
		    int n=sc.nextInt(),k=sc.nextInt();
		    int a[]=new int[n],i=0,days=0,min=Integer.MAX_VALUE;
		    while(i<n)
		        a[i++]=sc.nextInt();
		    for(i=1; i<=100; i++){
		        days=0;
		        for(int j=0; j<n;){
		            if(a[j]==i){
		               j++;
		               continue;
		            }
		            days++;
		            j+=k;
		        }
		        min = Math.min(days,min);
		    }

		    System.out.println(min);
		}
	}
}


//@author->.....future_me......//

//..............Learning.........//

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class B {

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static class FastReader {
    BufferedReader  br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static FastReader  sc  = new FastReader();
  static PrintWriter out = new PrintWriter(System.out);

  static int            mod = 1000000007;
  static ArrayList<dis> aa;
  static int            dis[][];

  public static void main(String[] args) throws Exception {
//    try {

    int t = sc.nextInt();
    while (t-- > 0)
      B.go();

//    } catch (Exception e) {
//      return;
//    }
  }

  static void go() {
    int n = sc.nextInt();
    int k = sc.nextInt();
    int a[] = new int[n];

    LinkedHashSet<Integer> set = new LinkedHashSet<>();
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();

      set.add(a[i]);
    }

    int ans = Integer.MAX_VALUE;
    for (int j = 1; j <= 100; j++) {

      int i = 0;
      int c = 0;
      int s = j;
      while (i < n) {
        int maxx = 0;
        int count = 0;
        if (a[i] == s) {
          i++;
          continue;
        }
        while (i < n && maxx < k) {
          maxx++;
          i++;
          count++;
        }
        if (count != 0) {
          c++;
        }
      }

      ans = Math.min(ans, c);
    }
    System.out.println(ans);
  }

  static int solve(int a[], int l, int r) {
    if (r == l) {
      return 1;
    }
    int max = 0;
    for (int i = l; i <= r; i++) {
      max = Math.max(dis[l][i], max);
    }

    return max;
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static void sort(long[] a) {
    ArrayList<Long> aa = new ArrayList<>();
    for (long i : a) {
      aa.add(i);
    }
    Collections.sort(aa);
    for (int i = 0; i < a.length; i++)
      a[i] = aa.get(i);
  }

  static long pow(long x, long y) {
    long res = 1l;
    while (y != 0) {
      if (y % 2 == 1) {
        res = x * res;
      }
      y /= 2;
      x = x * x;
    }
    return res;
  }

}

class dis {
  int x;
  int y;

  dis(int x, int y) {
    this.x = x;
    this.y = y;
  }
}


//@author->.....future_me......//

//..............Learning.........//

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class B {

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static class FastReader {
    BufferedReader  br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static FastReader  sc  = new FastReader();
  static PrintWriter out = new PrintWriter(System.out);

  static int            mod = 1000000007;
  static ArrayList<dis> aa;
  static int            dis[][];

  public static void main(String[] args) throws Exception {
//    try {

    int t = sc.nextInt();
    while (t-- > 0)
      B.go();
    out.flush();
//    } catch (Exception e) {
//      return;
//    }
  }

  static void go() {
    int n = sc.nextInt();
    int k = sc.nextInt();
    int a[] = new int[n];

    LinkedHashSet<Integer> set = new LinkedHashSet<>();
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();

      set.add(a[i]);
    }

    int ans = Integer.MAX_VALUE;
    for (int j : set) {

      int i = 0;
      int c = 0;
      int s = j;
      while (i < n) {
        int maxx = 0;
        int count = 0;
        if (a[i] == s) {
          i++;
        }
        while (i < n && maxx < k && a[i] != s) {

          if (count == 0) {
            count++;
            c++;
          }
          maxx++;
          i++;
        }

      }

      ans = Math.min(ans, c);
    }
    System.out.println(ans);
  }

  static int solve(int a[], int l, int r) {
    if (r == l) {
      return 1;
    }
    int max = 0;
    for (int i = l; i <= r; i++) {
      max = Math.max(dis[l][i], max);
    }

    return max;
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static void sort(long[] a) {
    ArrayList<Long> aa = new ArrayList<>();
    for (long i : a) {
      aa.add(i);
    }
    Collections.sort(aa);
    for (int i = 0; i < a.length; i++)
      a[i] = aa.get(i);
  }

  static long pow(long x, long y) {
    long res = 1l;
    while (y != 0) {
      if (y % 2 == 1) {
        res = x * res;
      }
      y /= 2;
      x = x * x;
    }
    return res;
  }

}

class dis {
  int x;
  int y;

  dis(int x, int y) {
    this.x = x;
    this.y = y;
  }
}


//@author->.....future_me......//

//..............Learning.........//

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class B {

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static class FastReader {
    BufferedReader  br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static FastReader  sc  = new FastReader();
  static PrintWriter out = new PrintWriter(System.out);

  static int            mod = 1000000007;
  static ArrayList<dis> aa;
  static int            dis[][];

  public static void main(String[] args) throws Exception {
//    try {

    int t = sc.nextInt();
    while (t-- > 0)
      B.go();
    out.flush();
//    } catch (Exception e) {
//      return;
//    }
  }

  static void go() {
    int n = sc.nextInt();
    int k = sc.nextInt();
    int a[] = new int[n];
    int fq[] = new int[101];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      fq[a[i]]++;
    }
    int max = -1;
    int s = 0;
    for (int i = 0; i < 101; i++) {
      if (fq[i] > max) {
        max = fq[i];
        s = i;
      }
    }
    int i = 0;
    int c = 0;

    boolean f = false;
    while (i < n) {
      int maxx = 0;
      while (i < n && a[i] == s) {
        i++;
      }

      while (i < n && maxx < k && a[i] != s) {

        if (f == false) {
          c++;
          f = true;
        }
        maxx++;
        i++;
      }
      f = false;

    }
    System.out.println(c);
  }

  static int solve(int a[], int l, int r) {
    if (r == l) {
      return 1;
    }
    int max = 0;
    for (int i = l; i <= r; i++) {
      max = Math.max(dis[l][i], max);
    }

    return max;
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static void sort(long[] a) {
    ArrayList<Long> aa = new ArrayList<>();
    for (long i : a) {
      aa.add(i);
    }
    Collections.sort(aa);
    for (int i = 0; i < a.length; i++)
      a[i] = aa.get(i);
  }

  static long pow(long x, long y) {
    long res = 1l;
    while (y != 0) {
      if (y % 2 == 1) {
        res = x * res;
      }
      y /= 2;
      x = x * x;
    }
    return res;
  }

}

class dis {
  int x;
  int y;

  dis(int x, int y) {
    this.x = x;
    this.y = y;
  }
}


//@author->.....future_me......//

//..............Learning.........//

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class B {

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static class FastReader {
    BufferedReader  br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static FastReader  sc  = new FastReader();
  static PrintWriter out = new PrintWriter(System.out);

  static int            mod = 1000000007;
  static ArrayList<dis> aa;
  static int            dis[][];

  public static void main(String[] args) throws Exception {
//    try {

    int t = sc.nextInt();
    while (t-- > 0)
      B.go();
    out.flush();
//    } catch (Exception e) {
//      return;
//    }
  }

  static void go() {
    int n = sc.nextInt();
    int k = sc.nextInt();
    int a[] = new int[n];
    int fq[] = new int[101];
    HashSet<Integer> set = new HashSet<>();
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      fq[a[i]]++;
      set.add(a[i]);
    }
    int max = -1;
    int s = 0;
    for (int i = 0; i < 101; i++) {
      if (fq[i] > max) {
        max = fq[i];
        s = i;
      }
    }

    boolean f = false;
    int ans = Integer.MAX_VALUE;
    for (int j : set) {

      int i = 0;
      int c = 0;

      while (i < n) {
        int maxx = 0;
        while (i < n && a[i] == j) {
          i++;
        }

        while (i < n && maxx < k && a[i] != j) {

          if (f == false) {
            c++;
            f = true;
          }
          maxx++;
          i++;
        }
        f = false;

      }
      ans = Math.min(ans, c);
    }
    System.out.println(ans);
  }

  static int solve(int a[], int l, int r) {
    if (r == l) {
      return 1;
    }
    int max = 0;
    for (int i = l; i <= r; i++) {
      max = Math.max(dis[l][i], max);
    }

    return max;
  }

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static void sort(long[] a) {
    ArrayList<Long> aa = new ArrayList<>();
    for (long i : a) {
      aa.add(i);
    }
    Collections.sort(aa);
    for (int i = 0; i < a.length; i++)
      a[i] = aa.get(i);
  }

  static long pow(long x, long y) {
    long res = 1l;
    while (y != 0) {
      if (y % 2 == 1) {
        res = x * res;
      }
      y /= 2;
      x = x * x;
    }
    return res;
  }

}

class dis {
  int x;
  int y;

  dis(int x, int y) {
    this.x = x;
    this.y = y;
  }
}