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 static java.lang.Math.*;

public class Contest {
    public static class pair implements Comparable<pair> {
        int l;
        int r;
        int dif;

        public pair(int lef, int ri) {
            l = lef;
            r = ri;
            dif = r - l;
        }

        @Override
        public int compareTo(pair p) {
            if (p.dif == dif)
                return l - p.l;
            return p.dif - dif;
        }
    }

    static int n, m;
    static ArrayList<Integer>[] adj;
    static int dist[];
    static int parent[];
    static long inf = (long) 1e16;
    static int INF = (int) 1e9;

    public static int[] bfs(int s) {
        dist = new int[n];
        Arrays.fill(dist, -1);
        dist[s] = 0;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        while (!q.isEmpty()) {
            int u = q.poll();
            for (int v : adj[u])
                if (dist[v] == -1) {
                    dist[v] = dist[u] + 1;
                    q.add(v);
                }
        }
        return dist;
    }

    public static long calc(long[] acc, int single, int Dbl) {
        if (single + Dbl > m) return inf;
        return acc[Dbl] + acc[single + Dbl];
    }

    public static boolean subset(TreeSet<Integer> small, TreeSet<Integer> big) {
        for (int x : small)
            if (!big.contains(x))
                return false;
        return true;
    }

    public static TreeSet<Integer> subset2(TreeSet<Integer> small, TreeSet<Integer> big) {
        TreeSet<Integer> ts = new TreeSet<>();
        for (int x : small)
            if (!big.contains(x))
                ts.add(x);
        return ts;
    }

    public static boolean CanBeStart(int x, TreeSet<Integer>[] Arr) {
        TreeSet<Integer> last = new TreeSet<>();
        for (int j = 0; j < n - 1; j++)
            if (Arr[j].contains(x)) {
                if (!subset(last, Arr[j]))
                    return false;
                last = Arr[j];
            }
        return true;
    }

    public static boolean check(TreeSet<Integer> sublist, ArrayList<Integer> arr) {
        int len = sublist.size(), n = arr.size();
        for (int i = 0; i < n - len + 1; i++) {
            boolean flag = true;
            for (int j = 0; j < len; j++)
                if (!sublist.contains(arr.get(i + j)))
                    flag = false;
            if (flag) return true;
        }
        return false;
    }

    public static boolean check(TreeSet<Integer>[] Arr, ArrayList<Integer> arr) {
        boolean ans = true;
        for (int i = 0; i < n - 1; i++)
            ans &= check(Arr[i], arr);
        return ans;
    }

    public static boolean alltrue(boolean[] arr) {
        for (boolean flag : arr)
            if (flag) return false;
        return true;
    }

    public static boolean sep(boolean[] arr) {
        boolean open = false;
        int cnt = 0;
        for (int i = 0; i < arr.length; i++)
            if (open) {
                if (!arr[i]) open = false;
            } else {
                if (arr[i]) {
                    open = true;
                    cnt++;
                }
            }
        return cnt <= 1;
    }


    static int[] dx = new int[]{-1, 1, 0, 0};
    static int[] dy = new int[]{0, 0, -1, 1};
    static boolean[][] Matrix, vis;

    static boolean valid(int i, int j) {
        return i != -1 && j != -1 && i != n && j != m && Matrix[i][j];
    }

    static void dfs2(int i, int j) {
        vis[i][j] = true;                        //mark as visited
        for (int k = 0; k < 4; ++k) {
            int x = i + dx[k], y = j + dy[k];
            if (valid(x, y) && !vis[x][y])
                dfs2(x, y);
        }
    }

    public static boolean isSimilar(char[] Arr, int s, int k) {
        for (int i = s; i < k - 1; i++) {
            if (Arr[i + 1] != Arr[i])
                return false;
        }
        return true;
    }

    public static int ciel(int d, int mod) {
        if (d % mod == 0)
            return d / mod;
        return d / mod + 1;
    }

    public static long lcm(long u, long v) {
        return (v / gcd(u, v)) * u;
    }

    public static long gcd(long u, long v) {
        if (v == 0)
            return u;
        return gcd(v, u % v);
    }

    public static void calc(int idx, int v, int[] arr) {
        for (int x : arr)
            pw.print(x + idx * v + " ");

    }

    public static int dp(int idx) {
        if (idx >= n)
            return INF;
        if(memo[idx]!=-1)
            return memo[idx];
       int ans=1-Arr[idx];
       int left=lefAcc[idx+k-1]-lefAcc[idx];
       return memo[idx]=ans+min(riAcc[idx+1],left+dp(idx+k));

    }

    static int[] four = new int[]{2, 4, 1, 3};
    static int[] five = new int[]{1, 4, 2, 5, 3};
    static int[] six = new int[]{1, 4, 2, 6, 3, 5};
    static int[] seven = new int[]{1, 5, 3, 6, 2, 4, 7};
    static PrintWriter pw;
    static int k, Arr[], lefAcc[], riAcc[];
    static int memo[];
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            k = sc.nextInt();
            String str = sc.next();
            Arr = new int[n + 1];
            for (int i = 0; i < n; i++)
                Arr[i] = str.charAt(i) - '0';
            lefAcc = new int[n + 1+n];
            riAcc = new int[n + 1];
            lefAcc[0] = Arr[0];
            for (int i = 1; i < n; i++)
                lefAcc[i] = lefAcc[i - 1] + Arr[i];
            for (int i = n - 1; i >= 0; i--)
                riAcc[i] = riAcc[i + 1] + Arr[i];
            memo=new int[n];
          Arrays.fill(memo,-1);
            int ans = dp(0);
            for (int i = 1; i < n; i++) {
                ans = min(ans, lefAcc[i-1]+dp(i));
            }

            pw.println(min(ans,riAcc[0]));

        }


        pw.close();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException, IOException {
            return br.ready();
        }

    }
}
