#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    long long int thy;
    cin>>thy;
    for (long long int pp = 0; pp < thy; pp++)
    {

        long long int n, k;
        cin >> n >> k;
        string w1;
        cin >> w1;
        long long int i = 0;
        long long int latin;
        if (w1[0] == '0' && w1[1] == '1')
        {
            w1[0] = '1';
        }
        if (w1[n - 1] == '0' && w1[n - 2] == '1')
        {
            w1[n - 1] = '1';
        }
        long long int gcf = 0;
        long long int gcff = 0;
        for (long long int hg = 0; hg < n; hg++)
        {
            if (w1[hg] == '1')
            {
                gcf = 1;
                break;
            }
        }
        if (gcf == 0)
        {
            cout << w1 << endl;
            continue;
        }
        for (long long int hg = 0; hg < n - 1; hg++)
        {
            if (w1[hg] == '0')
            {
                gcff++;
            }
            else
            {
                break;
            }
        }
        if (gcff >= 2)
        {
            long long int df = 0;
            //cout<<"jj"<<endl;
            for (long long int mj = gcff - 1; mj >= 0 && df < k; mj--)
            {
                w1[mj] = '1';
                df++;
            }
        }

        while (i < n)
        {
            if (w1[i] == '1')
            {
                long long int u = i + 1;
                long long int count = 0;
                while (w1[u] != '1' && u < n)
                {
                    u++;
                    count++;
                }
                latin = u;
                if (count <= 1)
                {
                    i++;
                    continue;
                }
                if (count % 2 == 0)
                {
                    if (count <= k)
                    {
                        for (long long int j = i + 1; j < u; j++)
                        {
                            w1[j] = '1';
                        }
                    }
                    else
                    {
                        long long int dj = 0;
                        if (u == n)
                        {
                            for (long long int h = i + 1; h < n && dj < k; h++)
                            {
                                w1[h] = '1';
                                dj++;
                            }
                        }
                        else
                        {
                            for (long long int j = i + 1, mm = i + count; j < mm, dj < k; j++, mm--)
                            {
                                w1[j] = '1';
                                w1[mm] = '1';
                                dj++;
                            }
                        }
                    }
                }
                else
                {
                    if (count <= k)
                    {

                        if (u == n)
                        {
                            long long int dj = 0;
                            for (long long int h = i + 1; h < n && dj < k; h++)
                            {
                                w1[h] = '1';
                                dj++;
                            }
                        }
                        else
                        {

                            long long int ff = i + 1;
                            long long int bbb = count + i;
                            long long int halo = (ff + bbb) / 2;
                            for (long long int km = ff; km < u; km++)
                            {
                                if (km != halo)
                                {
                                    w1[km] = '1';
                                }
                            }
                        }
                    }
                    else
                    {
                        long long int dj = 0;
                        if (u == n)
                        {
                            for (long long int h = i + 1; h < n && dj < k; h++)
                            {
                                w1[h] = '1';
                                dj++;
                            }
                        }
                        else
                        {
                            for (long long int j = i + 1, mm = i + count; j < mm && dj < k; j++, mm--)
                            {
                                w1[j] = '1';
                                w1[mm] = '1';
                                dj++;
                            }
                        }
                    }
                }
                i = latin;
            }
            else
            {
                i++;
            }
        }

        cout << w1 << endl;
    }
}