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

 
 public class Main	{
	static class node{
		int a, b;
		public node(int x, int y) {
			a = x;
			b = y;
		}
	}
   static class Pair implements Comparable<Pair>{

	   int a;
	   int b;
//	   int ind;
//	   public Pair(int x, long y) {a = x;b=y;}
	   public Pair(int x, int y) {a = x;b=y;}
//	   public Pair(int x,int y, int z){a=x;b=y;ind = z;}
	   public int compareTo(Pair p){
		   if(a == p.a)
			   return b - p.b;
		   else
			   return a - p.a;
	   }
//		@Override
//		public int hashCode() {
//			final int prime = 31;
//			int result = 1;
//			result = prime * result + a;
//			result = prime * result + b;
//		   
//			return result;
//		}
//		@Override
//		public boolean equals(Object obj) {
//			Pair cur = (Pair)obj;
//			if((a==cur.a && b==cur.b))return true;
//			return false;
//		}
 } 

public static void main(String[] args) throws Exception {
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
public static long gcd(long a,long b)
{
  if(a<b)
    return gcd(b,a);
  if(b==0)
    return a;
  return gcd(b,a%b);
  
}
static long lcm(int a,int b) {
  return  a*b / gcd(a,b);
}
    
static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}

static long[]fact,inv_fact;
static long my_inv(long a) {
	return pow(a,mod-2);
}
static long bin(int a,int b) {
	if(a < b || a<0 || b<0)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
	
static void make_facts() {
  fact=new long[mxN];
  inv_fact = new long[mxN];
  fact[0]=inv_fact[0]=1L;
  for(int i=1;i<mxN;i++) {
	   fact[i] = (i*fact[i-1])%mod;
	   inv_fact[i] = my_inv(fact[i]);
  }
}
static void lazy(int st, int e, int tn) {
	if(lazy[tn] != INF) {
		tree[tn] = Math.min(tree[tn], lazy[tn]);
		if(st != e) {
			lazy[2*tn] = Math.min(lazy[2*tn], lazy[tn]);
			lazy[2*tn+1] = Math.min(lazy[2*tn+1], lazy[tn]);
		}
		lazy[tn] = INF;
	}
}
static void update(int ind, int val, int st, int e, int tn) {
	if(st == e) {
		tree[tn] = val;
		return;
	}
	int mid = (st + e) >> 1;	
  	if(ind <= mid)
		update(ind, val, st, mid, 2*tn);
  	else
		update(ind, val, mid+1, e, 2*tn+1);
	tree[tn] = Math.min(tree[2*tn], tree[2*tn+1]);
}
static int query(int l, int r, int st, int e, int tn) {
	if(st > r || e < l)return INF;
	
	if(st >= l && e <= r) {
		return tree[tn];
	}

	int mid = (st + e) >> 1;
	int x = query(l, r, st, mid, 2 * tn);
	int y = query(l, r, mid+1, e, 2 * tn + 1);
	return Math.min(x, y);
}
static final long mxx = (long)(3e18+5);
static final int mxN = (int)(1e5);
static final int mxV = (int)(1e5+5);
static long mod = (long)(1e9+7); //998244353;//
static int[]tree, lazy;
static final int INF = (int)1e9+5;
static boolean[]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, q, t, k, p;
static int[]a, fc;
static char[]arr;
static int rec(int i) {
	if(i == n-1) {
		return (arr[i] == '1' ? 1 : 0); 
	}
	int res = 0;
	res = fc[i+k] - fc[i];
	return res;
}
public static void solve() throws Exception {
   // solve the problem here
   MyScanner s = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int tc = s.nextInt();
        
        while(tc-->0){
        	n = s.nextInt();
        	k = s.nextInt();
        	arr = s.next().toCharArray();
        	int[]dp1 = new int[n], dp2 = new int[n]; // dp[i] -> min moves required to turn string 0..i k periodic with ith bit = 1
        	fc = new int[n];
        	for(int i=0; i<n; i++) {
        		if(i > 0)fc[i] += fc[i-1];
        		fc[i] += (arr[i] == '1' ? 1 : 0);
        	}
        	int ans = fc[n-1];
        	for(int i=0; i<n; i++) {
        		dp1[i] = ((arr[i] - '0') ^ 1) + (i > 0 ? fc[i-1] : 0);
        		if (i >= k){
        			dp1[i] = Math.min(dp1[i], ((arr[i] - '0') ^ 1) + (fc[i-1] > 0 ? dp1[i-k] + (fc[i-1] - fc[i-k]) : 0));
        		}
        	}
//        	for(int i=n-1; i>=0; i--) {
//        		if(i + k > n - 1) {
//        			dp2[i] = ((arr[i] - '0') ^ 1) + (fc[n-1] - fc[i]);
//        		}
//        		else {
//        			dp2[i] = ((arr[i] - '0') ^ 1) + (fc[n-1] - fc[i] > 0 ? dp2[i+k] + (fc[i+k-1] - fc[i]) : 0);
//        		}
//        	}
//        	for(int i=0; i<n; i++) {
//        		out.print(dp1[i] + " ");
//        	}out.println();
//        	for(int i=0; i<n; i++) {
//        		out.print(dp2[i] + " ");
//        	}out.println();
        	for(int i=0; i<n; i++) {
        		ans = Math.min(ans, dp1[i] + fc[n-1] - fc[i]);
        	}
        	out.println(ans);
        	
        }
        	
           
        out.flush();
}
 
	     
 
 
 
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
 
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public MyScanner() {
            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;
        }
    }
    //--------------------------------------------------------
}

