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.*;

public class Main {
    public static int getSum(int i, int j, ArrayList<Integer> pref) {
        if (i >= 0 && j < pref.size() && i <= j) {
            if (i == 0)
                return pref.get(j);
            return pref.get(j) - pref.get(i - 1);
        }
        return 0;
    }

    public static int go(int x, int y, ArrayList<Integer> arr, ArrayList<Integer> pref, int[][] dp) {
        int n = arr.size();
        for (int j = 0; j < 2; j++)
            dp[n][j] = 0;
        for (int i = n - 1; i >= 0; i--) {
            for (int j = 0; j < 2; j++) {
                if (j == 0)
                    dp[i][j] = getSum(i, arr.size() - 1, pref);
                else {
                    int temp = Math.min(dp[i + 1][1], dp[i + 1][0]);
                    if (arr.get(i) == 1)
                        dp[i][j] = Math.min(dp[i][j], temp);
                    else
                        dp[i][j] = Math.min(dp[i][j], 1 + temp);
                }
            }
        }
        return dp[x][y];
    }

    public static void solve(Scanner in, PrintWriter out) {
        try {
            int n, k, total;
            n = in.nextInt();
            k = in.nextInt();
            total = 0;
            String str = in.next();
            ArrayList<ArrayList<Integer>> info = new ArrayList<ArrayList<Integer>>();
            for (int i = 0; i < k; i++) {
                ArrayList<Integer> temp_arr = new ArrayList<Integer>();
                for (int j = i; j < n; j += k) {
                    total += (str.charAt(j) - '0');
                    temp_arr.add(str.charAt(j) - '0');
                }
                info.add(temp_arr);
            }
            int ans = (int) 1e9;
            for (int i = 0; i < info.size(); i++) {
                ArrayList<Integer> pref = new ArrayList<Integer>(info.get(i).size());
                pref.add(0, info.get(i).get(0));
                int on = info.get(i).get(0);
                for (int j = 1; j < info.get(i).size(); j++) {
                    pref.add(j, pref.get(j - 1) + info.get(i).get(j));
                    on += info.get(i).get(j);
                }
                int[][] dp = new int[info.get(i).size() + 1][2];
                for (int j = 0; j < info.get(i).size() + 1; j++)
                    dp[j][0] = dp[j][1] = (int) 1e9;
                int fix = 0;
                int temp = Math.min(go(0, 1, info.get(i), pref, dp), go(0, 0, info.get(i), pref, dp));
                for (int j = 0; j < info.get(i).size(); j++) {
                    temp = Math.min(dp[j][1], dp[j][0]);
                    ans = Math.min(ans, total - on + fix + temp);
                    fix += info.get(i).get(j);
                }
            }
            out.println(ans);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String args[]) {
        try {
            Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int t = 1;
            t = in.nextInt();
            for (int tc = 1; tc <= t; tc++)
                solve(in, out);
            in.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
}