#include <bits/stdc++.h>
using namespace std;
long long int z = 1000000009;
bool aya[400005];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string s, s1, s2;
    cin >> s;
    s1 = s;
    s1 += '2';
    long long int c = 1;
    vector<long long int> v;
    for (long long int i = 1; i < n + 1; i++) {
      if (s1[i] == s1[i - 1])
        c++;
      else {
        v.push_back(c);
        c = 1;
      }
    }
    if (s[0] == '0') {
      while (v[0]--) s2 += '0';
      v.erase(v.begin());
    }
    long long int last = 0;
    if (s[n - 1] == '1') {
      last = v[v.size() - 1];
      v.erase(v.begin() + v.size() - 1);
    }
    long long int l = v.size();
    if (l > 1) {
      long long int c1 = 0;
      for (long long int i = 0; i < l - 1; i += 2) {
        if (k > 0) {
          long long int k1 = v[i] + c1, k2 = v[i + 1];
          long long int p = k / k1, q = k % k1;
          long long int req1 = min(k2, p);
          k2 -= req1;
          if (k2 == 0) q = 0;
          k -= (k1 * req1 + q);
          while (req1--) s2 += '0';
          if (k == 0 || i == l - 2) {
            long long int r = k1 - q;
            while (r--) s2 += '1';
            if (q) s2 += '0';
            k2 = max(k2 - q, (long long int)0);
            while (q--) s2 += '1';
            while (k2--) s2 += '0';
            break;
          }
          c1 += v[i];
        }
      }
    }
    long long int l1 = s2.length();
    cout << s2;
    if (l1 < n) {
      for (long long int i = l1; i < n; i++) {
        cout << s[i];
      }
    }
    cout << "\n";
  }
}
