#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int FreqCount[100001] = {0};
//    int RememberIndex[100001];
    vector <int> RememberIndex;

    int n;
    cin >> n;

    int InPut[100009] = {0};
//    int OutPut[100001];
    vector <int> OutPut;

    int MAX = 0; /// need the max number so that if 1 does not exist we will replace it with the max number at the very end;

    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        InPut[i] = x;

        MAX = max(x,MAX);

        if(FreqCount[x] >= 1) /// this number has repeatation
        {
            RememberIndex.push_back(x);  /// remembering the index of repeated numbers; need to sort it!
        }

        if(FreqCount[x] == 0) /// these numbers are totally brand new. no repeat for these. direct o/p
        {
            OutPut.push_back(x);
        }

        FreqCount[x]++;
    }

    sort(RememberIndex.begin(),RememberIndex.end());

    if(FreqCount[1] == 0) /// if number 1 does not exist
    {
        FreqCount[MAX]--;  /// the value of max will be swaped for the 1st index;
        OutPut.insert(OutPut.begin()+0,1);
        FreqCount[1]++;

    }

    for(int i=0;i<RememberIndex.size();i++)
    {
        int x = RememberIndex[i];
        for(int j=2;j<100001;j++)
        {
            if(FreqCount[x] == 1) /// if the repetation decrease to 1
            {
//                OutPut.push_back(x);
                break;
            }

            else if(FreqCount[j] == 0)/// found an empty place
            {
                FreqCount[j]++; /// put a new item in the empty place

                FreqCount[x]--; /// repetation of the number has decreased by 1

            }

        }

    }

    for(int i=1;i<10;i++)
    {
        if(FreqCount[i] == 1)cout << i<< " ";
//            cout << FreqCount[i]<< " ";
    } cout  << endl;

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, j;
    int *v1, *v2, *v3;
    //printf("Introduza n:");
    scanf("%d", &n);
    v1=(int *)malloc(n*sizeof(int));
    v2=(int *)calloc(n, sizeof(int));
    v3=(int *)calloc(n, sizeof(int));

    //printf("Introduza a sequencia de numeros:");
    for(i=0; i<n; i++)
    {
        scanf("%d", &v1[i]);
        if(v1[i]<=n)
        {
        	v2[v1[i]-1]++;        //Calcula a frequencia de cada numero, vetor v2
		}
    }

    for(i=0, j=0; i<n; i++)
    {
        if(v2[i]==0)             //Se não aparece na sequencia
            v3[j++]=i+1;         //Imprimo este numero no vetor v3
    }

    for(i =0; i<n; i++)
    {
    	printf("%d   ", v3[i]);
	}
    for(i=0, j=0; i<n; i++)
    {
        if(v2[v1[i]-1]>1)        //Se o numero repete mais de uma vez
        {
            v2[(v1[i]-1)]--;     //retiro uma unidade de frequencia do vetor v2 para o numero repetido
            v1[i]=v3[j++];       //substituo no vetor original v1 o numero faltante
        }
        else if(v1[i]>n)
        {
            v1[i]=v3[j++];       //Se o numero não pertence a sequencia de 1 a n, ele também deve ser substituído
        }
    }

    //printf("A sequencia correta e: ");

    for(i=0; i<n; i++)
    {
        printf("%d ", v1[i]);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, j;
    int *v1, *v2, *v3;

    scanf("%d", &n);
    v1=(int *)malloc(n*sizeof(int));
    v2=(int *)calloc(n, sizeof(int));
    v3=(int *)calloc(n, sizeof(int));

    for(i=0; i<n; i++)
    {
        scanf("%d", &v1[i]);
        if(v1[i]<=n)
        {
        	v2[v1[i]-1]++;        //Calcula a frequencia de cada numero, vetor v2
		}
    }

    for(i=0, j=0; i<n; i++)
    {
        if(v2[i]==0)             //Se não aparece na sequencia
            v3[j++]=i+1;         //Imprimo este numero no vetor v3
    }
    for(i=0, j=0; i<n; i++)
    {
        if(v2[v1[i]-1]>1)        //Se o numero repete mais de uma vez
        {
            v2[(v1[i]-1)]--;     //retiro uma unidade de frequencia do vetor v2 para o numero repetido
            v1[i]=v3[j++];       //substituo no vetor original v1 o numero faltante
        }
        else if(v1[i]>n)
        {
            v1[i]=v3[j++];       //Se o numero não pertence a sequencia de 1 a n, ele também deve ser substituído
        }
    }

    //printf("A sequencia correta e: ");

    for(i=0; i<n; i++)
    {
        printf("%d      ", v1[i]);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, j;
    int *v1, *v2, *v3;
    //printf("Introduza n:");
    scanf("%d", &n);
    v1=(int *)malloc(n*sizeof(int));
    v2=(int *)calloc(n, sizeof(int));
    v3=(int *)calloc(n, sizeof(int));

    //printf("Introduza a sequencia de numeros:");
    for(i=0; i<n; i++)
    {
        scanf("%d", &v1[i]);
        if(v1[i]<=n)
        {
        	v2[(v1[i]-1)]++;        //Calcula a frequencia de cada numero, vetor v2
		}
    }

    for(i=0, j=0; i<n; i++)
    {
        if(v2[i]==0)             //Se não aparece na sequencia
            v3[j++]=i+1;         //Imprimo este numero no vetor v3
    }
    for(i=0, j=0; i<n; i++)
    {
    	if(v1[i]>n)
        {
            v1[i]=v3[j++];       //Se o numero não pertence a sequencia de 1 a n, ele também deve ser substituído
        }
        else if(v2[(v1[i]-1)]>1)        //Se o numero repete mais de uma vez
        {
            v2[(v1[i]-1)]--;     //retiro uma unidade de frequencia do vetor v2 para o numero repetido
            v1[i]=v3[j++];       //substituo no vetor original v1 o numero faltante
        }
    }

    //printf("A sequencia correta e: ");

    for(i=0; i<n; i++)
    {
        printf("%d      ", v1[i]);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, j;
    int *v1, *v2, *v3;
    //printf("Introduza n:");
    scanf("%d", &n);
    v1=(int *)malloc(n*sizeof(int));
    v2=(int *)calloc(n, sizeof(int));
    v3=(int *)calloc(n, sizeof(int));

    //printf("Introduza a sequencia de numeros:");
    for(i=0; i<n; i++)
    {
        scanf("%d", &v1[i]);
        if(v1[i]<=n)
        {
        	v2[(v1[i]-1)]++;        //Calcula a frequencia de cada numero, vetor v2
		}
    }

    for(i=0, j=0; i<n; i++)
    {
        if(v2[i]==0)             //Se não aparece na sequencia
            v3[j++]=i+1;         //Imprimo este numero no vetor v3
    }
    for(i=0, j=0; i<n; i++)
    {
        if(v2[(v1[i]-1)]>1)        //Se o numero repete mais de uma vez
        {
            v2[(v1[i]-1)]--;     //retiro uma unidade de frequencia do vetor v2 para o numero repetido
            v1[i]=v3[j++];       //substituo no vetor original v1 o numero faltante
        }
        else if(v1[i]>n)
        {
            v1[i]=v3[j++];       //Se o numero não pertence a sequencia de 1 a n, ele também deve ser substituído
        }
    }

    //printf("A sequencia correta e: ");

    for(i=0; i<n; i++)
    {
        printf("%d      ", v1[i]);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, j;
    int *v1, *v2, *v3;
    //printf("Introduza n:");
    scanf("%d", &n);
    v1=(int *)malloc(n*sizeof(int));
    v2=(int *)calloc(n, sizeof(int));
    v3=(int *)calloc(n, sizeof(int));

    //printf("Introduza a sequencia de numeros:");
    for(i=0; i<n; i++)
    {
        scanf("%d", &v1[i]);
        if(v1[i]<=n)
        {
        	v2[v1[i]-1]++;        //Calcula a frequencia de cada numero, vetor v2
		}
    }

    for(i=0, j=0; i<n; i++)
    {
        if(v2[i]==0)             //Se não aparece na sequencia
            v3[j++]=i+1;         //Imprimo este numero no vetor v3
    }
    for(i=0, j=0; i<n; i++)
    {
        if(v2[v1[i]-1]>1)        //Se o numero repete mais de uma vez
        {
            v2[(v1[i]-1)]--;     //retiro uma unidade de frequencia do vetor v2 para o numero repetido
            v1[i]=v3[j++];       //substituo no vetor original v1 o numero faltante
        }
        else if(v1[i]>n)
        {
            v1[i]=v3[j++];       //Se o numero não pertence a sequencia de 1 a n, ele também deve ser substituído
        }
    }

    //printf("A sequencia correta e: ");

    for(i=0; i<n; i++)
    {
        printf("%d      ", v1[i]);
    }
    return 0;
}


/*
    iaaaaaaahhhhhhhh
*/
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define pi pair< int,int >
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");

void print_b(ll x);
void pshiet(){printf("%s","shiet");}

ll n,k;
string s;
bool check(string s){

int j=s.length()-1;
while (s[j]=='1'&&j>=0) j--;
for (;j>=0;j--) if (s[j]=='1') return false;
return true;

}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;

    while(t--){
        cin>>n>>k;
        cin>>s;
        int j =0;
        int i0=0;
        int i1=0;
        int cnt=0;
        while(k>0){
            //i0=0;
            i1=0;
            while(i0<n-1&&s[i0]=='1') i0++;
            while(i1<n-1&&s[i1]=='0') i1++;

            //cout<<i0<<" "<<i0-min((ll)(i0-i1),k) <<endl;
            //continue;
            //cout<<s[i0]<<" "<<s[i0- min((ll)(i0-i1),k) ]<<endl;
            swap( s[i0] , s[ i0-min((ll)(i0-i1),k)  ]  );

            cnt++;
            k-=min((ll)(i0-i1),k);
            //cout<<"k: "<<k<<endl;
            if (j==n-1) break;
            //cout<<s<<endl;
            //swap(i1,i0);
            //i0++;
        }
        cout<<s<<endl;

    }
}

void print_b(ll x){
if (x<0|x>(1<<31-1)) {
    cout<<"ovf";
    return;
}
for (int i = 31 - __builtin_clz(x);i>=0;i--)
    cout<< ((x&(1<<i))>0) ?  1 : 0 ;
}


/*
    iaaaaaaahhhhhhhh
*/
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define pi pair< int,int >
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");

void print_b(ll x);
void pshiet(){printf("%s","shiet");}

ll n,k;
string s;
bool check(string s){

int j=s.length()-1;
while (s[j]=='1'&&j>=0) j--;
for (;j>=0;j--) if (s[j]=='1') return false;
return true;

}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;

    while(t--){
        cin>>n>>k;
        cin>>s;
        int j =0;
        int i0=0;
        int i1=0;
        int cnt=0;
        while(k>0){
            //i0=0;
            //i1=0;
            while(i0<n-1&&s[i0]=='1') i0++;
            while(i1<n-1&&s[i1]=='0') i1++;

            //cout<<i0<<" "<<i0-min((ll)(i0-i1),k) <<endl;
            //continue;
            //cout<<s[i0]<<" "<<s[i0- min((ll)(i0-i1),k) ]<<endl;
            swap( s[i0] , s[ i0-min((ll)(i0-i1),k)  ]  );

            cnt++;
            k-=min((ll)(i0-i1),k);
            //cout<<"k: "<<k<<endl;
            if (j==n-1) break;
            //cout<<s<<endl;
            //swap(i1,i0);
            i0=i1;
            i0++;
            if (check(s)) break;
        }
        cout<<s<<endl;

    }
}

void print_b(ll x){
if (x<0|x>(1<<31-1)) {
    cout<<"ovf";
    return;
}
for (int i = 31 - __builtin_clz(x);i>=0;i--)
    cout<< ((x&(1<<i))>0) ?  1 : 0 ;
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
ll n, k;
vector<int> v;

template <class T>
struct BIT {
///1-indexed
int sz, mod;
vector<T> t;
  void init(int n) { //(declare init(int n, int m) for mod)
    sz = n;
    //mod = m;
    t.assign(sz, 0);
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for(; idx >= 1; idx -= (idx & -idx)) ans = (ans + t[idx]);
    return ans;
  }
  void upd(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    //val = (val + mod) % mod;
    for(; idx < sz; idx += (idx & -idx)) t[idx] = (t[idx] + val);
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  //T query(int l, int r) { return (query(r) - query(l - 1) + mod)%mod; }
  T query(int l, int r) { return query(r) - query(l - 1); }
};

char ans[1000010];
ll cum[maxn], idx[maxn], fin[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
        fin[i] = i;
        idx[i] = 1;
      }
    }
    cum[0] = idx[0];
    for (int i = 1; i < n; ++i) cum[i] = cum[i - 1] + idx[i];
    int lstzero = -1;
    BIT<int> a;
    a.init(n + 1);
    int id = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      //cout << "->" << i << " " << dif << endl;
      //cout << "k = " << k << endl;
      int lft = pos - dif;
      int rgt = pos - 1;
      fin[pos] = lft;
      lstzero = lft;
      int zeroes = 0;
      if (lft == 0) zeroes = cum[rgt];
      else zeroes = cum[rgt] - cum[lft - 1];
      //cout << "---" << lft << " " << rgt << " " << zeroes << endl;
      if (rgt < lft) continue;
      lft -= zeroes;
      lft = max(0, lft);
      a.upd(lft, rgt, 1);

      //cout << lft << " " << pos << endl;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        int idx = a.query(i) + i;
        ans[idx] = s[i];
        //cout << "1 " << i << " " << idx << endl;
      }
      else {
        ans[fin[i]] = s[i];
        //cout << "0 " << i << " " << fin[i] << endl;
      }
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
    memset(idx, 0, sizeof idx);
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
ll n, k;
vector<int> v;

char ans[1000010];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
      }
      ans[i] = '1';
    }
    int lstzero = -1;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      //if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      int lft = pos - dif;
      int rgt = pos - 1;
      ans[lft] = '0';
      lstzero = lft;
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
int n, k;
vector<int> v;

template <class T>
struct BIT {
///1-indexed
int sz, mod;
vector<T> t;
  void init(int n) { //(declare init(int n, int m) for mod)
    sz = n;
    //mod = m;
    t.assign(sz, 0);
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for(; idx >= 1; idx -= (idx & -idx)) ans = (ans + t[idx]);
    return ans;
  }
  void upd(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    //val = (val + mod) % mod;
    for(; idx < sz; idx += (idx & -idx)) t[idx] = (t[idx] + val);
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  //T query(int l, int r) { return (query(r) - query(l - 1) + mod)%mod; }
  T query(int l, int r) { return query(r) - query(l - 1); }
};

char ans[100010];
ll cum[maxn], idx[maxn], fin[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
        fin[i] = i;
        idx[i] = 1;
      }
    }
    cum[0] = idx[0];
    for (int i = 1; i < n; ++i) cum[i] = cum[i - 1] + idx[i];
    int lstzero = -1;
    BIT<int> a;
    a.init(n + 1);
    int id = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      //cout << "->" << i << " " << dif << endl;
      //cout << "k = " << k << endl;
      int lft = pos - dif;
      int rgt = pos - 1;
      fin[pos] = lft;
      lstzero = lft;
      int zeroes = 0;
      if (lft == 0) zeroes = cum[rgt];
      else zeroes = cum[rgt] - cum[lft - 1];
      //cout << "---" << lft << " " << rgt << " " << zeroes << endl;
      if (rgt < lft) continue;
      lft -= zeroes;
      lft = max(0, lft);
      a.upd(lft, rgt, 1);

      //cout << lft << " " << pos << endl;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        int idx = a.query(i) + i;
        ans[idx] = s[i];
        //cout << "1 " << i << " " << idx << endl;
      }
      else {
        ans[fin[i]] = s[i];
        //cout << "0 " << i << " " << fin[i] << endl;
      }
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
    memset(idx, 0, sizeof idx);
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
ll n, k;
vector<int> v;

template <class T>
struct BIT {
///1-indexed
int sz, mod;
vector<T> t;
  void init(int n) { //(declare init(int n, int m) for mod)
    sz = n;
    //mod = m;
    t.assign(sz, 0);
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for(; idx >= 1; idx -= (idx & -idx)) ans = (ans + t[idx]);
    return ans;
  }
  void upd(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    //val = (val + mod) % mod;
    for(; idx < sz; idx += (idx & -idx)) t[idx] = (t[idx] + val);
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  //T query(int l, int r) { return (query(r) - query(l - 1) + mod)%mod; }
  T query(int l, int r) { return query(r) - query(l - 1); }
};

char ans[1000010];
ll cum[maxn], idx[maxn], fin[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
        fin[i] = i;
        idx[i] = 1;
      }
      else idx[i] = 0;
    }
    cum[0] = idx[0];
    for (int i = 1; i < n; ++i) cum[i] = cum[i - 1] + idx[i];
    int lstzero = -1;
    BIT<int> a;
    a.init(n + 1);
    int id = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      //cout << "->" << i << " " << dif << endl;
      //cout << "k = " << k << endl;
      int lft = pos - dif;
      int rgt = pos - 1;
      fin[pos] = lft;
      lstzero = lft;
      int zeroes = 0;
      if (rgt < lft) continue;
      if (lft == 0) zeroes = cum[rgt];
      else zeroes = cum[rgt] - cum[lft - 1];
      //cout << "---" << lft << " " << rgt << " " << zeroes << endl;

      lft -= zeroes;
      lft = max(0, lft);
      a.upd(lft, rgt, 1);

      //cout << lft << " " << pos << endl;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        int idx = a.query(i) + i;
        ans[idx] = s[i];
        //cout << "1 " << i << " " << idx << endl;
      }
      else {
        ans[fin[i]] = s[i];
        //cout << "0 " << i << " " << fin[i] << endl;
      }
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
int n, k;
vector<int> v;

template <class T>
struct BIT {
///1-indexed
int sz, mod;
vector<T> t;
  void init(int n) { //(declare init(int n, int m) for mod)
    sz = n;
    //mod = m;
    t.assign(sz, 0);
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for(; idx >= 1; idx -= (idx & -idx)) ans = (ans + t[idx]);
    return ans;
  }
  void upd(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    //val = (val + mod) % mod;
    for(; idx < sz; idx += (idx & -idx)) t[idx] = (t[idx] + val);
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  //T query(int l, int r) { return (query(r) - query(l - 1) + mod)%mod; }
  T query(int l, int r) { return query(r) - query(l - 1); }
};

char ans[100010];
ll cum[maxn], idx[maxn], fin[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
        fin[i] = i;
        idx[i] = 1;
      }
    }
    cum[0] = idx[0];
    for (int i = 1; i < n; ++i) cum[i] = cum[i - 1] + idx[i];
    int lstzero = -1;
    BIT<int> a;
    a.init(n + 1);
    int id = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      //cout << "->" << i << " " << dif << endl;
      if (k < dif) dif = k;
      k -= dif;
      //cout << "k = " << k << endl;
      int lft = pos - dif;
      int rgt = pos - 1;
      fin[pos] = lft;
      lstzero = lft;
      int zeroes = 0;
      if (lft == 0) zeroes = cum[rgt];
      else zeroes = cum[rgt] - cum[lft - 1];
      lft -= zeroes;
      lft = max(0, lft);
      a.upd(lft, rgt, 1);

      //cout << lft << " " << pos << endl;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        int idx = a.query(i) + i;
        ans[idx] = s[i];
        //cout << "1 " << i << " " << idx << endl;
      }
      else {
        ans[fin[i]] = s[i];
        //cout << "0 " << i << " " << fin[i] << endl;
      }
    }
    ans[n] = '\0';
    cout << ans << endl;
    //for (int i = 0; i < n; ++i) cout << ans[i];
    //cout << endl;
    v.clear();
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
int n, k;
vector<int> v;

template <class T>
struct BIT {
///1-indexed
int sz, mod;
vector<T> t;
  void init(int n) { //(declare init(int n, int m) for mod)
    sz = n;
    //mod = m;
    t.assign(sz, 0);
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for(; idx >= 1; idx -= (idx & -idx)) ans = (ans + t[idx]);
    return ans;
  }
  void upd(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    //val = (val + mod) % mod;
    for(; idx < sz; idx += (idx & -idx)) t[idx] = (t[idx] + val);
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  //T query(int l, int r) { return (query(r) - query(l - 1) + mod)%mod; }
  T query(int l, int r) { return query(r) - query(l - 1); }
};

char ans[1000010];
ll cum[maxn], idx[maxn], fin[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
        fin[i] = i;
        idx[i] = 1;
      }
    }
    cum[0] = idx[0];
    for (int i = 1; i < n; ++i) cum[i] = cum[i - 1] + idx[i];
    int lstzero = -1;
    BIT<int> a;
    a.init(n + 1);
    int id = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      //cout << "->" << i << " " << dif << endl;
      //cout << "k = " << k << endl;
      int lft = pos - dif;
      int rgt = pos - 1;
      fin[pos] = lft;
      lstzero = lft;
      int zeroes = 0;
      if (lft == 0) zeroes = cum[rgt];
      else zeroes = cum[rgt] - cum[lft - 1];
      //cout << "---" << lft << " " << rgt << " " << zeroes << endl;
      if (rgt < lft) continue;
      lft -= zeroes;
      lft = max(0, lft);
      a.upd(lft, rgt, 1);

      //cout << lft << " " << pos << endl;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        int idx = a.query(i) + i;
        ans[idx] = s[i];
        //cout << "1 " << i << " " << idx << endl;
      }
      else {
        ans[fin[i]] = s[i];
        //cout << "0 " << i << " " << fin[i] << endl;
      }
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
    memset(idx, 0, sizeof idx);
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
ll n, k;
vector<int> v;

template <class T>
struct BIT {
///1-indexed
int sz, mod;
vector<T> t;
  void init(int n) { //(declare init(int n, int m) for mod)
    sz = n;
    //mod = m;
    t.assign(sz, 0);
  }
  T query(int idx) {
    idx++;
    T ans = 0;
    for(; idx >= 1; idx -= (idx & -idx)) ans = (ans + t[idx]);
    return ans;
  }
  void upd(int idx, T val) {
    idx++;
    if (idx <= 0) return;
    //val = (val + mod) % mod;
    for(; idx < sz; idx += (idx & -idx)) t[idx] = (t[idx] + val);
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  //T query(int l, int r) { return (query(r) - query(l - 1) + mod)%mod; }
  T query(int l, int r) { return query(r) - query(l - 1); }
};

char ans[1000010];
ll cum[maxn], idx[maxn], fin[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
        fin[i] = i;
        idx[i] = 1;
      }
      else idx[i] = 0;
    }
    cum[0] = idx[0];
    for (int i = 1; i < n; ++i) cum[i] = cum[i - 1] + idx[i];
    int lstzero = -1;
    BIT<int> a;
    a.init(n + 1);
    int id = 0;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      //cout << "->" << i << " " << dif << endl;
      //cout << "k = " << k << endl;
      int lft = pos - dif;
      int rgt = pos - 1;
      fin[pos] = lft;
      lstzero = lft;
      int zeroes = 0;
      if (lft == 0) zeroes = cum[rgt];
      else zeroes = cum[rgt] - cum[lft - 1];
      //cout << "---" << lft << " " << rgt << " " << zeroes << endl;
      if (rgt < lft) continue;
      lft -= zeroes;
      lft = max(0, lft);
      a.upd(lft, rgt, 1);

      //cout << lft << " " << pos << endl;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') {
        int idx = a.query(i) + i;
        ans[idx] = s[i];
        //cout << "1 " << i << " " << idx << endl;
      }
      else {
        ans[fin[i]] = s[i];
        //cout << "0 " << i << " " << fin[i] << endl;
      }
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
  }
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 1000010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

string s;
ll n, k;
vector<int> v;

char ans[1000010];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0') {
        v.push_back(i);
      }
      ans[i] = '1';
    }
    int lstzero = -1;
    for (int i = 0; i < (int)v.size(); ++i) {
      int pos = v[i];
      if (k == 0) break;
      int dif = pos - lstzero - 1;
      if (k < dif) dif = k;
      k -= dif;
      int lft = pos - dif;
      int rgt = pos - 1;
      ans[lft] = '0';
      lstzero = lft;
    }
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
    v.clear();
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0;
		for(int y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";

			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>=0){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cout<<s.substr(y+1);
					cnt=0;
					break;
				}
			}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0;
		for(int y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";

			//if(s[y]=='1') cnt++;
			if(s[y]=='0'){
				if(cnt<=k){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cout<<s.substr(y+1);
					cnt=0;
					break;
				}
			}else cnt++;
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0,y;
		for(y=0;y<s.length();y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";

			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>=0){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cnt=0;
					break;
				}
			}

		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";
		for(int i=y+1;i<s.length();i++) cout<<s[i];
		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0,y;
		for(y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";
			if(y<n){
			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>=0){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cnt=0;
					break;
				}
			}
		}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";
		for(int i=y+1;i<n;i++) cout<<s[i];
		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0,y;
		for(y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";
			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>=0){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cnt=0;
					break;
				}
			}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";
		for(int i=y+1;i<n;i++) cout<<s[i];
		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0;
		for(int y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";

			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cout<<s.substr(y+1);
					cnt=0;
					break;
				}
			}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0,y;
		for(y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";
			if(y<n){
			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>=0){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cout<<s.substr(y+1);
					cnt=0;
					break;
				}
			}
		}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0,y;
		for(y=0;y<n;y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";
			if(y<n){
			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>=0){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					for(int j=y+1;j<n;j++) cout<<s[j];
					cnt=0;
					break;
				}
			}
		}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0;
		for(int y=0;y<s.length();++y)
		{
			//cout<<y<<"\n"<<cnt<<" ";

			//if(s[y]=='1') cnt++;
			if(s[y]=='0'){
				if(cnt<=k){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cout<<s.substr(y+1);
					cnt=0;
					break;
				}
			}else cnt++;
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t;
    cin>>t;
    for(int it=0;it<t;it++)
    {
        ll n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        int ones=0,ind=0;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]=='1') ones++;
            else{
                if(k>=ones){
                    k-=ones;
                    cout<<"0";ind++;
                }else{
                    for(int j=0;j<ones-k;j++)
                    {cout<<"1";ind++;}
                    ones=k;
                    k=0;
                    cout<<"0";
                    for(int j=0;j<ones;j++){
                        cout<<"1";ind++;
                    }
                    ones=0;
                    ind++;
                    //ind=i+1;
                    break;
                }
                if(k==0){
                    //ind=i+1;
                    break;
                }
            }
        }
        for(int i=0;i<ones;i++){
            cout<<"1";
            ind++;
        }
        for(int i=ind;i<s.length();i++) cout<<s[i];
        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0,y;
		for(y=0;y<n;y++)
		{
			if(s[y]=='1') cnt++;
			else{
				if(cnt<=k&&cnt>0){
					cout<<"0";
					k-=cnt;
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cnt=0;
					break;
				}
			}
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";
		for(int i=y+1;i<n;i++) cout<<s[i];
		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,n,k;
	string s;
	cin>>q;
	for(int it=0;it<q;it++)
	{
		cin>>n>>k;
		cin>>s;
		int cnt=0;
		for(int y=0;y<s.length();y++)
		{
			//cout<<y<<"\n"<<cnt<<" ";

			//if(s[y]=='1') cnt++;
			if(s[y]=='0'){
				if(cnt<=k){
					cout<<"0";
					k-=cnt;
				//	cout<<y<<" ";
				}else{
					for(int j=0;j<cnt-k;j++) cout<<"1";
					cout<<"0";
					for(int j=0;j<k;j++) cout<<"1";
					cout<<s.substr(y+1);
					cnt=0;
					break;
				}
			}else cnt++;
		}
		//cout<<y<<" ";
		for(int i=0;i<cnt;i++) cout<<"1";

		cout<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ll q;
    cin>>q;
    string st;
    while(q--){
        ll n,k;
        cin>>n>>k;
        cin>>st;
        ll cnt1=0,so_far=0,flag=0;
        string res="";
        for(ll i=0;i<n;i++){
            if(st[i]=='1'){
                cnt1++;
            }
            else{
                k-=cnt1;
                if(k>=0){
                    res+='0';
                    so_far++;
                }
                else{
                    k=k+cnt1;
                    flag=1;
                    break;
                }
            }
        }
        if(flag){
            for(ll i=0;i<cnt1-k;i++){
                res+='1';
                so_far++;
            }
            res+='0';
            so_far++;
            for(ll i=0;i<k;i++){
                res+='1';
                so_far++;
            }
        }
        else{
            for(ll i=0;i<cnt1;i++){
                res+='1';
                so_far++;
            }
        }
        cout<<so_far<<endl;
        for(ll i=so_far;i<n;i++){
            res+=st[i];
        }
        cout<<res<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[1000001];
void trySwap(ll a[], ll start, ll end, ll *rem)
  {
//cout << start << "  " << end << "  " << *rem << endl;
  while (*rem != 0 && end > start)
  {
    if (a[end - 1] > a[end])
    {
        swap(a[end - 1], a[end]);
        (*rem)--;
        end--;
    }
    else end--;
}
}

void getMinimalLexicographicArray(ll a[], ll size, ll k)
{
ll start , rem = k, window = k;

for (start = 0; start < size; start++)
{
    window = rem;
    if (rem == 0)
        return;
    else
    {
        //cout << start << " " << rem << endl;
        ll end = start + window;
        if (end >= size)
        {
            end = size - 1;
        }
        trySwap(a, start, end, &rem);
    }
}
}

int main(){
    ll q;
    cin>>q;
    string st;
    while(q--){
        ll n,k;
        cin>>n>>k;
        cin>>st;
        for(ll i=0;i<n;i++){
            if(st[i]=='1'){
                a[i]=1;
            }
            else{
                a[i]=0;
            }
        }
        getMinimalLexicographicArray(a, n, k);
        for(ll i=0;i<n;i++){
            cout<<a[i];
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int a[1000001];
void trySwap(int a[], int start, int end, int *rem)
  {
//cout << start << "  " << end << "  " << *rem << endl;
  while (*rem != 0 && end > start)
  {
    if (a[end - 1] > a[end])
    {
        swap(a[end - 1], a[end]);
        (*rem)--;
        end--;
    }
    else end--;
}
}

void getMinimalLexicographicArray(int a[], int size, int k)
{
int start , rem = k, window = k;

for (start = 0; start < size; start++)
{
    window = rem;
    if (rem == 0)
        return;
    else
    {
        //cout << start << " " << rem << endl;
        int end = start + window;
        if (end >= size)
        {
            end = size - 1;
        }
        trySwap(a, start, end, &rem);
    }
}
}

int main(){
    int q;
    cin>>q;
    string st;
    while(q--){
        int n,k;
        cin>>n>>k;
        cin>>st;
        for(int i=0;i<n;i++){
            if(st[i]=='1'){
                a[i]=1;
            }
            else{
                a[i]=0;
            }
        }
        getMinimalLexicographicArray(a, n, k);
        for(int i=0;i<n;i++){
            cout<<a[i];
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[1000001];
void trySwap(ll a[], ll start, ll end, ll *rem)
  {
//cout << start << "  " << end << "  " << *rem << endl;
  while (*rem != 0 && end > start)
  {
    if (a[end - 1] > a[end])
    {
        swap(a[end - 1], a[end]);
        (*rem)--;
        end--;
    }
    else end--;
}
}

void getMinimalLexicographicArray(ll a[], ll size, ll k)
{
ll start , rem = k, window = k;

for (start = 0; start < size; start++)
{
    window = rem;
    if (rem == 0)
        return;
    else
    {
        //cout << start << " " << rem << endl;
        ll end = start + window;
        if (end >= size)
        {
            end = size - 1;
        }
        trySwap(a, start, end, &rem);
    }
}
}

int main(){

    ll q;
    cin>>q;
    string st;
    while(q--){for(ll i=0;i<1000001;i++){
        a[i]=0;
    }
        ll n,k;
        cin>>n>>k;
        cin>>st;
        for(ll i=0;i<n;i++){
            if(st[i]=='1'){
                a[i]=1;
            }
            else{
                a[i]=0;
            }
        }
        getMinimalLexicographicArray(a, n, k);
        for(ll i=0;i<n;i++){
            cout<<a[i];
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long ll
ll a[1000001];
void trySwap(ll a[], ll start, ll end, ll *rem)
  {
//cout << start << "  " << end << "  " << *rem << endl;
  while (*rem != 0 && end > start)
  {
    if (a[end - 1] > a[end])
    {
        swap(a[end - 1], a[end]);
        (*rem)--;
        end--;
    }
    else end--;
}
}

void getMinimalLexicographicArray(ll a[], ll size, ll k)
{
ll start , rem = k, window = k;

for (start = 0; start < size; start++)
{
    window = rem;
    if (rem == 0)
        return;
    else
    {
        //cout << start << " " << rem << endl;
        ll end = start + window;
        if (end >= size)
        {
            end = size - 1;
        }
        trySwap(a, start, end, &rem);
    }
}
}

ll main(){
    ll q;
    cin>>q;
    string st;
    while(q--){
        ll n,k;
        cin>>n>>k;
        cin>>st;
        for(ll i=0;i<n;i++){
            if(st[i]=='1'){
                a[i]=1;
            }
            else{
                a[i]=0;
            }
        }
        getMinimalLexicographicArray(a, n, k);
        for(ll i=0;i<n;i++){
            cout<<a[i];
        }
        cout<<endl;
    }
    return 0;
}


 #include <iostream>
  using namespace std;

  void trySwap(string a, int start, int end, int *rem)
  {
//cout << start << "  " << end << "  " << *rem << endl;
  while (*rem != 0 && end > start)
  {
      int t1=0,t2=0;
      if(a[end-1]=='1'){
          t1=1;
      }
      if(a[end]=='1'){
          t2=1;
      }
    if (t1 > t2)
    {
        swap(a[end - 1], a[end]);
        (*rem)--;
        end--;
    }
    else end--;
}
}

void getMinimalLexicographicArray(string a, int size, int k)
{
int start , rem = k, window = k;

for (start = 0; start < size; start++)
{
    window = rem;
    if (rem == 0)
        return;
    else
    {
        //cout << start << " " << rem << endl;
        int end = start + window;
        if (end >= size)
        {
            end = size - 1;
        }
        trySwap(a, start, end, &rem);
    }
}
}
int main()
{
int T, N, K;
string st;
int i, j;

cin >> T;
for (i = 0; i < T; i++)
{
    cin >> N>>K;
    cin>>st;

    getMinimalLexicographicArray(st, N, K);

    for (j = 0; j < N; j++)
        cout << st[j];
    cout << endl;

}

return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[1000001];
void trySwap(ll a[], ll start, ll end, ll *rem)
  {
//cout << start << "  " << end << "  " << *rem << endl;
  while (*rem != 0 && end > start)
  {
    if (a[end - 1] > a[end])
    {
        swap(a[end - 1], a[end]);
        (*rem)--;
        end--;
    }
    else end--;
}
}

void getMinimalLexicographicArray(ll a[], ll size, ll k)
{
ll start , rem = k, window = k;

for (start = 0; start < size; start++)
{
    window = rem;
    if (rem == 0)
        return;
    else
    {
        //cout << start << " " << rem << endl;
        ll end = start + window;
        if (end >= size)
        {
            end = size - 1;
        }
        trySwap(a, start, end, &rem);
    }
}
}

int main(){

    ll q;
    cin>>q;
    string st;
    while(q--){
        ll n,k;
        cin>>n>>k;
        cin>>st;
        for(ll i=0;i<n;i++){
            if(st[i]=='1'){
                a[i]=1;
            }
            else{
                a[i]=0;
            }
        }
        getMinimalLexicographicArray(a, n, k);
        for(ll i=0;i<n;i++){
            cout<<a[i];
            if(a[i]==1){
                a[i]=0;
            }
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ll q;
    cin>>q;
    string st;
    while(q--){
        ll n,k;
        cin>>n>>k;
        cin>>st;
        ll cnt1=0,so_far=0,flag=0;
        string res="";
        for(ll i=0;i<n;i++){
            if(st[i]=='1'){
                cnt1++;
            }
            else{
                k-=cnt1;
                if(k>=0){
                    res+='0';
                    so_far++;
                }
                else{
                    k=k+cnt1;
                    flag=1;
                    break;
                }
            }
        }
        if(flag){
            for(ll i=0;i<cnt1-k;i++){
                res+='1';
                so_far++;
            }
            res+='0';
            so_far++;
            for(ll i=0;i<k;i++){
                res+='1';
                so_far++;
            }
        }
        else{
            for(ll i=0;i<cnt1;i++){
                res+='1';
                so_far++;
            }
        }
        for(ll i=so_far;i<n;i++){
            res+=st[i];
        }
        cout<<res<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        int prev=0,i;
        int last=-1;
        for(i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,prev);
                for(int i=0; i<prev-agabe; i++) {
                    ans+='1';
                }
                ans+='0';
                k-=agabe;
                int t=prev-agabe;
                prev-=t;
                last=i;
            } else {
                prev++;
            }
        }
        while(prev>0){
            ans+='1';
            prev--;
        }
        for(int i=last+1; i<n; i++) {
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        int prev=0,i;
        int last=-1;
        set<int>ss;
        queue<int>q;
        for(int i=0;i<n;i++){
            ss.insert(i);
        }
        for(i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,prev);
                for(int j=0; j<prev-agabe && q.empty()==false; j++) {
                    ans+='1';
                    ss.erase(q.front());
                    q.pop();
                }
                ans+='0';
                ss.erase(i);
                k-=agabe;
                int t=prev-agabe;
                prev-=t;
                last=i;
            } else {
                prev++;
                q.push(i);
            }
        }
        for(int i:ss){
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set_rev = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        ordered_set<int>os1;
        ordered_set<int>os2;
        for(int i=0;i<s.size();i++){
            if(s[i]=='1'){
                os1.insert(i);
            }
            else{
                if(os1.empty()==false && k>0){
                    int xd=min(k,(int)os1.size());
                    int t=(int)os1.size()-xd;
                    auto itr=os1.fbo(t);
                    if(*itr<i){
                        k-=xd;
                        os2.insert(*itr);
                        os1.erase(*itr);
                        os1.insert(i);
                    }
                    else{
                        os2.insert(i);
                    }
                }
                else{
                    os2.insert(i);
                }
            }
        }
        for(int i=0;i<n;i++)ans+='0';
        for(int i:os1){
            ans[i]='1';
        }
        for(int i:os2){
            ans[i]='0';
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        set<int>ss;
        queue<int>q;
        for(int i=0;i<n;i++){
            ss.insert(i);
        }
        for(int i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,(int)q.size());
                for(int j=0; j<(int)q.size()-agabe; j++) {
                    ans+='1';
                    ss.erase(q.front());
                    q.pop();
                }
                ans+='0';
                ss.erase(i);
                k-=agabe;
            } else {
                q.push(i);
            }
        }
        for(int i:ss){
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        set<int>ss;
        queue<int>q;
        for(int i=0;i<n;i++){
            ss.insert(i);
        }
        for(i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,q.size());
                for(int i=0; i<q.size()-agabe && q.empty()==false; i++) {
                    ans+='1';
                    ss.erase(q.front());
                    q.pop();
                }
                ans+='0';
                ss.erase(i);
                k-=agabe;
            } else {
                q.push(i);
            }
        }
        for(int i:ss){
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        int prev=0,i;
        int last=-1;
        for(i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,prev);
                for(int i=0; i<prev-agabe; i++) {
                    ans+='1';
                }
                ans+='0';
                k-=agabe;
                int t=prev-agabe;
                prev-=t;
                last=i;
            } else {
                prev++;
            }
        }
        if(prev==n){
            cout<<s<<"\n";
            continue;
        }
        while(prev>0){
            ans+='1';
            prev--;
        }
        for(int i=last+1; i<n; i++) {
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set_rev = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n;
        ll k;
        scanf("%d %lld",&n,&k);
        string s;
        cin>>s;
        string ans="";
        ordered_set<int>os1;
        ordered_set<int>os2;
        for(int i=0;i<s.size();i++){
            if(s[i]=='1'){
                os1.insert(i);
            }
            else{
                if(os1.empty()==false && k>0){
                    int xd=min(k,(int)os1.size());
                    int t=(int)os1.size()-xd;
                    auto itr=os1.fbo(t);
                    if(*itr<i){
                        k-=xd;
                        os2.insert(*itr);
                        os1.erase(*itr);
                        os1.insert(i);
                    }
                    else{
                        os2.insert(i);
                    }
                }
                else{
                    os2.insert(i);
                }
            }
        }
        for(int i=0;i<n;i++)ans+='0';
        for(int i:os1){
            ans[i]='1';
        }
        for(int i:os2){
            ans[i]='0';
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        int prev=0,i;
        int last=-1;
        set<int>ss;
        queue<int>q;
        for(int i=0;i<n;i++){
            ss.insert(i);
        }
        for(i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,prev);
                for(int i=0; i<prev-agabe && q.empty()==false; i++) {
                    ans+='1';
                    ss.erase(q.front());
                    q.pop();
                }
                ans+='0';
                ss.erase(i);
                k-=agabe;
                int t=prev-agabe;
                prev-=t;
                last=i;
            } else {
                prev++;
                q.push(i);
            }
        }
        for(int i:ss){
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n,k;
        scanf("%d %d",&n,&k);
        string s;
        cin>>s;
        string ans="";
        set<int>ss;
        queue<int>q;
        for(int i=0;i<n;i++){
            ss.insert(i);
        }
        for(int i=0; i<n && k; i++) {
            if(s[i]=='0') {
                int agabe = min(k,(int)q.size());
                for(int i=0; i<q.size()-agabe && q.empty()==false; i++) {
                    ans+='1';
                    ss.erase(q.front());
                    q.pop();
                }
                ans+='0';
                ss.erase(i);
                k-=agabe;
            } else {
                q.push(i);
            }
        }
        for(int i:ss){
            ans+=s[i];
        }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set_rev = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    QUERY {
        int n;
        ll k;
        scanf("%d %lld",&n,&k);
        string s;
        cin>>s;
        string ans="";
        ordered_set<int>os1;
        ordered_set<int>os2;
        for(int i=0;i<s.size();i++){
            if(s[i]=='1'){
                os1.insert(i);
            }
            else{
                if(os1.empty()==false && k>0){
                    ll xd=min(k,(ll)os1.size());
                    ll t=(int)os1.size()-xd;
                    auto itr=os1.fbo(t);
                    if(*itr<i){
                        k-=xd;
                        os2.insert(*itr);
                        os1.erase(*itr);
                        os1.insert(i);
                    }
                    else{
                        os2.insert(i);
                    }
                }
                else{
                    os2.insert(i);
                }
            }
        }
        for(int i=0;i<n;i++)ans+='0';
        for(int i:os1){
            ans[i]='1';
        }
        for(int i:os2){
            ans[i]='0';
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long c,i,j,p=0,n,k,t=0;
    char s[200000];
    cin>>c;
    for(i=0;i<c;i++)
    {
        scanf("%lld%lld%s",&n,&k,s);
        t=k;
        p=0;
        for(j=0;j<n;j++)
        {
            if(s[j]=='1'&&s[j+1]=='0')
            {
                if(j+1<=t)
                {
                    swap(s[p],s[j+1]);
                    t=t-j-1;
                    p++;
                }
                else
                {
                    swap(s[j+1-t],s[j+1]);
                    break;
                }
            }
        }
        cout<<s<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long c,i,j,p=0,n,k;
    char s[2000000];
    cin>>c;
    for(i=0;i<c;i++)
    {
        scanf("%lld%lld%s",&n,&k,s);
        p=0;
        for(j=0;j<n&&k;j++)
        {
            if(s[j]=='1'){p++;}
            else if(s[j]=='0'&&p)
            {
                if(p<=k)
                {
                    swap(s[j-p],s[j]);
                    k-=p;
                }
                else
                {
                    swap(s[j-k],s[j]);
                    break;
                }
            }
        }
        cout<<s<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long c,i,j,p=0,n,k;
    char s[200000];
    cin>>c;
    for(i=0;i<c;i++)
    {
        scanf("%lld%lld%s",&n,&k,s);
        p=0;
        for(j=0;j<n&&k;j++)
        {
            if(s[j]=='1'){p++;}
            else if(s[j]=='0'&&p)
            {
                if(p<=k)
                {
                    swap(s[j-p],s[j]);
                    k-=p;
                }
                else
                {
                    swap(s[j-k],s[j]);
                    break;
                }
            }
        }
        cout<<s<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n, k, m, prev, ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = -1;
		rep(i, 0, n) {
			if (s[i] == '1' && prev == -1) {
				prev = i;
				continue;
			}
			if (s[i] == '0') {
				if (i - prev <= k) {
					s[i] = '1';
					s[prev] = '0';
					k = k - (i - prev);
					prev++;
				}
				else {
					s[i] = '1';
					s[i - k] = '0';
					k = 0;
					prev++;
				}
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev,ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = -1;
		rep(i, 0, n) {
			if (s[i] == '1' && prev == -1) {
				prev = i;
				continue;
			}
			if (s[i] == '0') {
				ind = min(k, i - prev);
				s[i] = '1';
				s[i - ind] = '0';
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev,ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = -1;
		rep(i, 0, n) {
			if (s[i] == '1' && prev == -1) {
				prev = i;
				continue;
			}
			if (s[i] == '0') {
				ind = min(k, i - prev);
				if (ind <= 0) {
					ind = 0;
				}
				if (ind > n - 1) {
					ind = n - 1;
				}
				s[i] = '1';
				s[i - ind] = '0';
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev,ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0' && i != 0) {
				ind = min(k, i - prev);
				s[i] = '1';
				s[i - ind] = '0';
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n, k, m, prev, ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0') {
				ind = min(k, 0LL + i - prev);
				swap(s[ind], s[i]);
				k -= ind;
				prev++;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev,ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = -1;
		rep(i, 0, n) {
			if (s[i] == '1' && prev == -1) {
				prev = i;
				continue;
			}
			if (s[i] == '0') {
				ind = min(k, i - prev);
				if (ind <= 0) {
					ind = 0;
				}
				if (ind > n - 1) {
					ind = n - 1;
				}
				if (i >= 0 && i < n) {
					s[i] = '1';
				}
				if ((i-ind) >= 0 && (i-ind) < n) {
					s[i - ind] = '0';
				}
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0' && i != 0) {

				if ((i - prev) <= k) {
					//cout << "if" << endl;
					//cout << "k:" << k << endl;
					s[prev] = '0';
					s[i] = '1';

					k =k-( i - prev);
					prev++;
				}
				else {
					//cout << "else" << endl;
					s[i - k] = '0';
					s[i] = '1';
					break;
				}
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n, k, m, prev, ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = -1;
		rep(i, 0, n) {
			if (s[i] == '1' && prev == -1) {
				prev = i;
				continue;
			}
			if (s[i] == '0') {
				ind = min(k, i - prev);
				s[i] = '1';
				s[prev] = '0';
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev,ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0' && i != 0 && s[prev]=='1') {
				ind = min(k, i - prev);
				s[i] = '1';
				s[i - ind] = '0';
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n, k, m, prev, ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0') {
				ind = min(k, 0LL + i - prev);
				swap(s[i-ind], s[i]);
				k -= ind;
				prev++;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n, k, m, prev, ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0') {
				if (i - prev < k) {
					swap(s[prev], s[i]);
					k -= i + prev;
					prev++;
				}
				else {
					swap(s[i - k], s[i]);
					k = 0;
				}
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n, k, m, prev, ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = 0;
		rep(i, 0, n) {
			if (s[i] == '0') {
				if (i - prev < k) {
					swap(s[prev], s[i]);
					k -= i + prev;
					prev++;
				}
				else {
					swap(s[i - k], s[i]);
					k = 0;
					break;
				}
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define rep(var,start,end) for(var=start;var<end;var++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	ll t, i, j, n,k,m,prev,ind;
	ll mod = 10000000;
	cin >> t;
	string s;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		prev = -1;
		rep(i, 0, n) {
			if (s[i] == '1' && prev == -1) {
				prev = i;
				continue;
			}
			if (s[i] == '0') {
				ind = min(k, i - prev);
				if (ind <= 0) {
					ind = 0;
				}
				if (ind > n - 1) {
					ind = n - 1;
				}
				if (i >= 0 && i < n) {
					s[i] = '1';
				}
				if (i >= 0 && i < n) {
					s[i - ind] = '0';
				}
				k -= ind;
				prev++;
			}
			if (k == 0) {
				break;
			}

		}
		cout << s << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int q,n,k;
string s;
set<int> pos;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> q;
	while(q--){
		cin >> n >> k;
		cin >> s;
		pos.clear();
		for(int i = 0;i < n;i++){
			if(s[i] == '1') pos.insert(i);
		}
		for(int i = 0;i < n;i++){
			if(k <= 0 || !pos.size()) break;
			if(s[i] == '0'){
				if(i < *pos.begin()) continue;
				int p = *pos.lower_bound(i - k);
				k -= (i - p);
				pos.erase(p);
				pos.insert(i);
			}
		}
		for(int i = 0;i < n;i++){
			if(pos.find(i) != pos.end()) cout << 1;
			else cout << 0;
		}
		cout << endl;
	}
	return 0;
}