#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

/*-------------------------------------*---------------------------------------*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef tuple<ll, ll, ll> tlll;

#define F(i, m, n) for (ll i = m; i < n; i++)
#define Fr(j, n, m) for (ll j = n; j >= m; j--)
#define ff first
#define ss second
#define min min<ll>
#define max max<ll>
#define all(c) c.begin(), c.end()
/*-------------------------------------*---------------------------------------*/

#define godspeed                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define deb(x) cout << #x << "=" << x << endl
#define cout_array(a)                                                          \
  cout << #a << "=";                                                           \
  for (auto x : a) {                                                           \
    cout << x << " ";                                                          \
  }                                                                            \
  cout << endl

/*-------------------------------------*---------------------------------------*/
/**
 * Calcultes greatest Common divison using Euclid's division Lemma
 * Use __gcd(a,b) : inbuilt function
 */

/**
 * Calculates (x^y)%z Using Binary Exponentiation . Similar to pow(x,y,z)
 * function of python
 *
 * @param   x,y Input numbers
 * @param   z if not specified default to 1e18
 * @returns pow(x,y) modulo z
 */

const ll MAX_PRIME = 1e9 + 7;
const ll INF = 1e18 + 1;
const pll EXTREMA = make_pair(INF, -INF);
ll fast_pow(ll x, ll y, ll z = INF) {
  if (y == 0)
    return 1 % z;
  else if (y == 1)
    return x % z;
  if (y % 2 == 0) {
    ll res = fast_pow(x, y / 2, z);
    return (res * res) % z;
  } else {
    ll res = fast_pow(x, y / 2, z);
    ll temp = (res * res) % z;
    return ((x % z) * temp) % z;
  }
}

/*-------------------------------------*---------------------------------------*/

/**
 * DFS
 * vis.clear();vis.assign(n,0);
 * adj.clear();adj.resize(n);
 */
const ll N = 1e5 + 1;
vll vis(N);
vvll adj(N);
void dfs(ll u) {
  if (vis[u])
    return;

  vis[u] = 1;

  for (ll v : adj[u]) {
    if (vis[v])
      continue;
    // do something
    dfs(v);
  }
  return;
}
/*-------------------------------------*---------------------------------------*/

/**
 * @author Abhay Mishra
 * @date   May 24 2021
 */
/*-------------------------------------*---------------------------------------*/

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  auto start = high_resolution_clock::now();
#endif
  godspeed;
  ll t;
  cin >> t;
  while (t--) {
    ll n,m;
    cin >> n>>m;
    string s;
    cin>>s;
    string b(n,'0');
    ll k = 0;
    vll a;
    F(i,0,n){
      if(s[i]=='1'){
        a.push_back(i);
        k = m;
        b[i] = '1';
      }
      else if(k>0){
        b[i] = '1';
        k--;
      }
    }
    k = 0;
    Fr(i,n-1,0){
      if(s[i]=='1'){
        k = m;
        b[i] = '1';
      }
      else if(k>0){
        b[i] = '1';
        k--;
      }
    }
    ll temp;
    F(i,1,a.size()){
      temp = (a[i] + a[i-1])/2;
      if(temp*2 != a[i]+a[i-1])continue;
      b[temp] = '0';
    }
    cout<<b<<endl;
  }
#ifndef ONLINE_JUDGE
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stop - start);
  cout << "Total Time taken to execute the program is :" << duration.count()
       << " ms" << endl;
#endif
  return 0;
}