#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
 
bool exists[(1<<20)];
int n_bound = 100000;

int main(){
    ios_base::sync_with_stdio(false);
    int T; cin >> T;
    for (int t=1;t<=T;t++){
        int n,k ; cin >> n >> k;
        string s; cin >> s;
        int cnt = 0;
        int bits_to_track = min(k, 20);
        int mask = (1 << bits_to_track) - 1;
        bool use_counting = (n > n_bound);
        if (use_counting)
            for (int i=0;i<=mask;i++) exists[i] = false;
        queue<int> inds;
        vector<int> exist_v;
        for (int i=0;i<n;i++){
            cnt <<= 1; //cnt *= 2
            cnt += (s[i] == '0'); //count the logical inverse of bits s[0 .. i]
            if (k > 20 && i >= 20){
                if (s[i-20] == '0') inds.push(i-20);
            }
            if (!inds.empty()){
                if (inds.front() + k -1 < i) inds.pop();
            }
            if (inds.empty() && i >= k-1){
                if (use_counting)
                    exists[cnt & mask] = true;
                else exist_v.push_back(cnt & mask);
            }
        }
        //for (int i=0;i<=mask;i++) cout << i << ": " << exists[i] << endl;
        int ans = -1;
        if (use_counting){
            for (int i=0;i<=mask;i++) {
                if (!exists[i]) {
                    ans = i;
                    break;
                }
            }
        } else {
            sort(exist_v.begin(), exist_v.end());
            int tmp = 0;
            for (int i=0;i<exist_v.size();i++){
                if (exist_v[i] == tmp)
                    tmp++;
            }
            if (tmp <= mask) ans = tmp;
        }
        if (ans == -1){
            cout << "NO\n";
        } else {
            cout << "YES\n";
            for (int i=0;i<k-bits_to_track;i++) cout << '0';
            for (int i=bits_to_track-1;i>=0;i--){
                if (ans & (1<<i)) cout << '1'; else cout << '0';
            }
            cout << endl;
        }
        
    }

}