#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int q, n, k;
char s[N], t[N];
int prefix[N];
int main() {
	scanf("%d", &q);
	while(q-- > 0) {
		scanf("%d %d", &n, &k);
		scanf("%s", s);
		int total = n - k + 1;
		int pw2 = 1;
		while((1 << pw2) <= total)
			pw2++;
		int remain = max(0, k - pw2);
		prefix[0] = (s[0] == '0');
		for(int i = 1; i < n; ++i)
			prefix[i] = prefix[i - 1] + (s[i] == '0');
		vector<bool> ignore(1 << min(k, pw2), false);
		for(int i = 0; i + k - 1 < n; ++i) {
			if(remain > 0) {
				int left = (i > 0) ? prefix[i - 1] : 0;
				if(prefix[i + remain - 1] - left > 0)
					continue;
			}
			int mask = 0;
			for(int j = i + k - 1, l = 0; j > i + remain - 1; --j, ++l)
				if(s[j] == '0')
					mask ^= (1 << l);
			ignore[mask] = true;
		}
		int ans = -1;
		for(int i = 0; i < (int) ignore.size(); ++i) {
			if(!ignore[i]) {
				ans = i;
				break;
			}
		}
		if(ans == -1) puts("NO");
		else {
			puts("YES");
			for(int i = 0; i < remain; ++i)
				t[i] = '0';
			for(int i = remain, j = min(k, pw2) - 1; i < k; ++i, --j)
				t[i] = (ans & (1 << j)) ? '1' : '0';
			for(int i = 0; i < k; ++i)
				putchar(t[i]);
			puts("");
		}
	}
	return 0;
}
