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 ≤ t ≤ 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 ≤ n ≤ 10^6; 1 ≤ k ≤ 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 (∑ n ≤ 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
import java.io.*;
import java.util.*;
//import java.util.HashMap;


//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.math.BigInteger;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.StringTokenizer;

public class Equal {
    static class tri implements Comparable<tri> {
        int inc;
        int dec;
        int sum;

        public tri(int xx, int modd, int s) {
            inc = xx;
            dec = modd;
            sum = s;
        }

        public int compareTo(tri o) {
            if (dec < o.dec)
                return -1;
            if (dec > o.dec)
                return 1;
            return 0;
        }

        @Override
        public boolean equals(Object obj) {
            return inc == ((tri) obj).inc && dec == ((tri) obj).dec;
        }
    }

    //    static long mem[][][];
    //    static long in[][];
    //    static int N, K;
    //
    //    static long dp(int i, int j, int p) {
    //        if (i >= N)
    //            return 0;
    //        if (j >= K)
    //            return 0;
    //        if (p <= 0)
    //            return 0;
    //        if (mem[i][j][p] != -1)
    //            return mem[i][j][p];
    //        return mem[i][j][p] = Math.max(in[i][j] + dp(i, j + 1, p - 1), Math.max(dp(i + 1, 0, p), in[i][j] + dp(i + 1, 0, p - 1)));
    //    }
    static int Replacements(tri[] arr, int sum) {
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].sum == sum) continue;
            if (sum < arr[i].sum) {
                if (arr[i].sum - sum <= arr[i].dec)
                    res++;
                else
                    res += 2;
            } else {
                if (sum - arr[i].sum <= arr[i].inc)
                    res++;
                else res += 2;
            }
        }
        return res;
    }

    static HashMap<Character, Integer>[] hms;
    static int[] p;
    static int[] rank;
    static char[] chars;

    static int findSet(int i) {
        return p[i] == i ? p[i] : (p[i] = findSet(p[i]));
    }

    static boolean inSameSet(int i, int j) {
        return findSet(i) == findSet(j);
    }

    static void union(int x, int y) {
        if (inSameSet(x, y)) return;
        int i = findSet(x);
        int j = findSet(y);
        if (rank[i] > rank[j]) {
            p[j] = i;

            return;
        }
        if (rank[i] < rank[j]) {
            p[i] = j;

        } else {
            p[j] = i;
            rank[i]++;
        }
    }

    static boolean[][] vis;
    static int w;
    static int h;
    static int[][] in;
    static int[][][] distance;
    static int[] xd = {0, 1, 0, -1};
    static int[] yd = {1, 0, -1, 0};

    public static int path(int i, int j, int length, int remove) {
        if (i < 0 || j < 0 || i == w || j == h || distance[i][remove][j] <= length)
            return 10000;
        if (in[i][j] == 1) {
            if (remove == 0)
                return 10000;
        }
        distance[i][remove][j] = length;
        // vis[i][j]=true;
        if (i == w - 1 && j == h - 1) {
            // vis[i][j]=false;
            return length;
        }
        if (in[i][j] == 1) {

            int ans = Math.min(path(i + xd[0], j + yd[0], length + 1, 0),
                    Math.min(path(i + xd[1], j + yd[1], length + 1, 0),
                            Math.min(path(i + xd[2], j + yd[2], length + 1, 0),
                                    path(i + xd[3], j + yd[3], length + 1, 0))));
            //vis[i][j]=false;
            return ans;
        }
        int ans = Math.min(path(i + xd[0], j + yd[0], length + 1, remove),
                Math.min(path(i + xd[1], j + yd[1], length + 1, remove),
                        Math.min(path(i + xd[2], j + yd[2], length + 1, remove),
                                path(i + xd[3], j + yd[3], length + 1, remove))));
        //vis[i][j]=false;
        return ans;


    }

    public static int solution(int[][] map) {
        // Your code here
        in = map;
        w = map.length;
        h = map[0].length;
        distance = new int[w][2][h];
        for (int i = 0; i < w; i++) {
            Arrays.fill(distance[i][0], 10000);
            Arrays.fill(distance[i][1], 10000);
        }

        return path(0, 0, 1, 1);
    }

    public static boolean checkAllSame(String[] c, int i, int im, int j, int jm) {
        for (int k = j; k < jm; k++) {
            for (int l = i + 1; l < im; l++) {
                if (c[l].charAt(k) != c[l - 1].charAt(k))
                    return false;
            }
        }
        return true;
    }

    public static boolean checkdiff(String[] c, int i, int im, int j, int jm, String comp) {
        for (int k = i; k < im; k++) {
            int diff = 0;
            for (int l = j; l < jm; l++) {
                if (c[k].charAt(l) != comp.charAt(l))
                    diff++;
            }
            if (diff > 1)
                return false;
        }
        return true;
    }

    static int[] mem;
    static int k;
    static int[] pres;
    static int[] ins;

    static int a5er1(int x) {

            if (x < 0 || x >= mem.length)
                return 0;
            if (mem[x] != -1)
                return mem[x];

            if (x == 0)
                return mem[x] = 1 - ins[x];
            if (x >= k)
                return mem[x] = 1 - ins[x] + Math.min(pres[x - 1], a5er1(x - k) + pres[x - 1] - pres[x - k]);

            return mem[x] = 1 - ins[x] + pres[x - 1];


    }

    public static void main(String[] args) throws IOException {
        //BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter out = new PrintWriter(System.out);
        int T = Integer.parseInt(br.readLine());
//        StringBuilder sb = new StringBuilder();
//        int x = 0;
//        ins = new int[100000];
//        pres = new int[100000];
//        mem = new int[100000];
//        Arrays.fill(mem, -1);
//        k = 1;
//        int sum = 0;
//        for (int i = 0; i < 100000; i++) {
//            ins[i] = 1 - x;
//            pres[i] = ins[i] + sum;
//            sum = pres[i];
//            x = 1 - x;
//        }
//        int n = 100000;
//        int min = pres[n - 1];
//        //System.err.println(a5er1(n-1));
//        for (int i = 0; i <n; i++) {
//            if (mem[i] == -1)
//                min = Math.min(min, a5er1(i) + pres[n - 1] - pres[i]);
//            else min = Math.min(min, mem[i] + pres[n - 1] - pres[i]);
//        }
//
//        out.println(min);

        while (T-- > 0) {
            st = new StringTokenizer(br.readLine());
            int n =Integer.parseInt(st.nextToken());
            k=Integer.parseInt(st.nextToken());
            mem=new int[n];
            Arrays.fill(mem,-1);
            String s=br.readLine();
            ins=new int[n];
            pres=new int[n];
            int sum=0;
            for (int i = 0; i <n ; i++) {
                ins[i]=Integer.parseInt(""+(s.charAt(i)));
                pres[i]=ins[i]+sum;
                sum=pres[i];
            }
            int min=pres[n-1];
            //System.err.println(a5er1(n-1));
            for (int i = 0; i <n ; i++) {
                if(mem[i]==-1)
                min=Math.min(min,a5er1(i)+pres[n-1]-pres[i]);
                else min=Math.min(min,mem[i]+pres[n-1]-pres[i]);
            }

            out.println(min);

        }
        out.flush();
        out.close();

    }

}
