#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define maxn 1000010
using namespace std;

int n, m;

char s[maxn];

int pre[maxn];

bool ban[maxn];

void work() {
    cin >> n >> m >> s + 1;
    vector<int> a; int v = 0, len = min(20, m), M = (1 << len) - 1;
    for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + (s[i] == '1'); 
    for (int i = 1; i < len; ++i) v = v * 2 + '1' - s[i];
    for (int i = len; i <= n; ++i) {
        v = v << 1 & M; v += '1' - s[i]; 
        if (i >= m && pre[i - len] - pre[i - m] == m - len) a.push_back(v), ban[v] = 1; 
    }
    bool ok = 0; vector<int> ans;
    for (int i = 1; i <= m - len; ++i) ans.push_back(0); 
    for (int i = 0; i <= M; ++i)
        if (!ban[i]) {
            for (int o = len - 1; ~o; --o) ans.push_back(i >> o & 1);
            ok = 1; break; 
        }
    for (auto u : a) ban[u] = 0; 
    if (!ok) cout << "NO\n";
    else {
        cout << "YES\n"; 
        for (auto u : ans) cout << u;
        cout << "\n"; 
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int T; cin >> T;
    while (T--) work(); 
    return 0;
} 
