You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.

In one move, you can choose one lamp and change its state (i.e. turn it on if it is turned off and vice versa).

The garland is called $k$-periodic if the distance between each pair of adjacent turned on lamps is exactly $k$. Consider the case $k=3$. Then garlands "00010010", "1001001", "00010" and "0" are good but garlands "00101001", "1000001" and "01001100" are not. Note that the garland is not cyclic, i.e. the first turned on lamp is not going after the last turned on lamp and vice versa.

Your task is to find the minimum number of moves you need to make to obtain $k$-periodic garland from the given one.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 25~ 000$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 10^6; 1 \le k \le n$) — the length of $s$ and the required period. The second line of the test case contains the string $s$ consisting of $n$ characters '0' and '1'.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ ($\sum n \le 10^6$).


-----Output-----

For each test case, print the answer — the minimum number of moves you need to make to obtain $k$-periodic garland from the given one.


-----Example-----
Input
6
9 2
010001010
9 3
111100000
7 4
1111111
10 3
1001110101
1 1
1
1 1
0

Output
1
2
5
4
0
0

Difficulty: introductory

Starter code:

Solutions:
import sys
input = sys.stdin.readline
rInt = lambda: int(input())
mInt = lambda: map(int, input().split())
rLis = lambda: list(map(int, input().split()))

outs = []

t = rInt()
for _ in range(t):
    n, k = mInt()
    s = input()

    pref = [0]
    for c in s:
        if c == '1':
            pref.append(pref[-1] + 1)
        else:
            pref.append(pref[-1])

    best = pref[-1]

    dp = []
    for i in range(n):
        cost = pref[i]
        if i >= k:
            case2 = dp[i - k] + pref[i] - pref[i - k + 1]
            if case2 < cost:
                cost = case2
        if s[i] == '0':
            cost += 1

        dp.append(cost)
        actual = cost + pref[-1] - pref[i + 1]
        if actual < best:
            best = actual

    outs.append(best)


print(*outs, sep = '\n')


import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')


def solve():
    n, k = nm()
    s = list(map(int, list(ns())))
    w = sum(s)
    sc = n
    for i in range(k):
        t = s[i::k]
        m = len(t)
        dp = [[0]*3 for j in range(m+1)]
        for j in range(m):
            dp[j+1][0] = dp[j][0] + t[j]
            dp[j+1][1] = min(dp[j][0], dp[j][1]) + 1 - t[j]
            dp[j+1][2] = min(dp[j][1], dp[j][2]) + t[j]
        sc = min(sc, min(dp[m]) + w - sum(t))
    print(sc)
    return




# solve()

T = ni()
for _ in range(T):
    solve()


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    n, k = rl()
    S = input()
    zero_blocks = dd(int)
    cost_all_zeros = 0
    rem = 0
    for i, c in enumerate(S):
        if c == '1':
            cost_all_zeros += 1
            zero_blocks[rem] += 1
        rem += 1
        if rem == k:
            rem = 0

    global_best = n
    for offset in range(k):
        zero_others = cost_all_zeros - zero_blocks[offset]

        pre, mid, post = 0, n, n
        for i in range(offset, n, k):
            if S[i] == '1':
                new_pre = pre + 1
                new_mid = min(mid, pre)
                new_post = min(post + 1, mid + 1)
            else:
                new_pre = pre
                new_mid = min(mid + 1, pre + 1)
                new_post = min(post, mid)
            pre, mid, post = new_pre, new_mid, new_post
        best = min(pre, mid, post)

        # print (offset, zero_others)
        # print (pre, mid, post)
        global_best = min(global_best, best + zero_others)


    print (global_best)
    # print ()



mode = 'T'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


import sys
strs = iter(sys.stdin.read().split())
ints = (int(x) for x in strs)
sys.setrecursionlimit(3000)

def main():
    ntc = next(ints)
    for tc in range(1,ntc+1):
        n, k = (next(ints) for i in range(2))
        s = next(strs)
        R = (n+k-1)//k
        m = [[int(i*k+j<n and s[i*k+j]=='1') for i in range(R)] for j in range(k)]
        s = [sum(m[j]) for j in range(k)]
        s_sum = sum(s)
        ans = [0]*k
        #0  1  1  0  1  0  1  1  0
        for j in range(k):
            off = [0]*(R+1)
            on  = [0]*(R+1)
            for i in range(R-1, -1, -1):
                off[i] = m[j][i] + off[i+1]
                on[i] = 1-m[j][i]+min(on[i+1], off[i+1])
            for i in range(R+1):
                off[i] = (i and off[i-1]) + (i<R and m[j][i])
                on[i] = on[i] + (i and off[i-1])
            ans[j] = s_sum-s[j] + min(on)
        print(min(ans))
    return

main()


t = int(input())
while t > 0 :
	t -= 1
	n, k = map(int, input().split())
	s = input()
	cnt, v = [0] * k, [list() for i in range(k)]
	ans = 0
	for i in range(n) :
		if s[i] == '1' :
			cnt[i % k] += 1
			ans += 1
		v[i % k].append(int(s[i]))
	tot = ans
	for i in range(k) :
		curAns = tot - cnt[i]
		tot0, tot1 = 0, 0
		mnsum = 0
		for j in range(len(v[i])) :
			if v[i][j] == 0 :
				tot0 += 1
			else :
				tot1 += 1
			ans = min(ans, curAns + mnsum + tot0 + (cnt[i] - tot1))
			mnsum = min(mnsum, tot1 - tot0)

	print(ans)