Chef has a binary string S of length N. He wonders if it is possible to divide S into exactly K non-empty [substrings] such that each S_{i} belongs to exactly one substring and the \texttt{XOR} of each substring is the same. Can you help Chef to determine if it is possible to do so?

Note: \texttt{XOR} of substring S_{L \cdots R} is defined as: \texttt{XOR} (S_{L \cdots R}) = S_{L} \oplus S_{L+1} \oplus \cdots \oplus S_{R}.

Here, \oplus denotes the [bitwise XOR operation].

------ Input Format ------ 

- The first line contains a single integer T - the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and K - the length of the binary string S and the number of substrings in which S has to be divided.
- The second line of each test case contains a binary string S of length N containing 0s and 1s only.

------ Output Format ------ 

For each test case, output YES if S can be divided into K substrings such that \texttt{XOR} of each substring is the same. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical).

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$1 ≤ K ≤N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$

----- Sample Input 1 ------ 
4
3 2
111
5 3
01100
8 3
01001111
6 2
000100

----- Sample Output 1 ------ 
NO
YES
YES
NO

----- explanation 1 ------ 
Test case 1: It can be proven that there is no way to divide $S = 111$ into $K = 2$ substrings such that $\texttt{XOR}$ of each substring is the same.

Test case 2: One of the possible ways of dividing $S$ is: $\underline{0}$ $\underline{11}$ $\underline{00}$. Here $\texttt{XOR}$ of each substring is $0$.

Test case 3: One of the possible ways of dividing $S$ is: $\underline{01}$ $\underline{001}$ $\underline{111}$. Here $\texttt{XOR}$ of each substring is $1$.

Test case 4: It can be proven that there is no way to divide $S = 000100$ into $K = 2$ substrings such that $\texttt{XOR}$ of each substring is the same.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Complete search

Bit manipulation

Mathematics

Greedy algorithms


Solutions:
n = int(input())
for i in range(1, n + 1):
	p = list(map(int, input().split()))
	n = p[0]
	k = p[1]
	s = input()
	c = 0
	count1 = 0
	f = 0
	v = 0
	for a in s:
		v ^= ord(a) - 48
		if v == 0:
			c += 1
	if c >= k and v != 1:
		f = 1
		print('YES')
	v = 0
	for a in s:
		v ^= ord(a) - 48
		if v == 1:
			count1 += 1
			v = 0
	if count1 >= k and (count1 - k) % 2 == 0:
		if f != 1:
			f = 1
			print('YES')
	if f == 0:
		print('NO')


T = int(input())
for t in range(1, T + 1):
	inp = input().split()
	N = int(inp[0])
	K = int(inp[1])
	S = input()
	Slist = []
	Slist[:0] = S
	Slist = list(map(int, Slist))
	num_0 = 0
	num_1 = 0
	xor_0 = xor_1 = 0
	for (i, s) in enumerate(Slist):
		xor_0 = xor_0 ^ s
		xor_1 = xor_1 ^ s
		if xor_0 == 0:
			num_0 += 1
		if xor_1 == 1:
			num_1 += 1
			xor_1 = 0
	if K > num_0 and K > num_1:
		print('NO')
	elif K <= num_0 and xor_0 == 0:
		print('YES')
	elif K <= num_1 and (num_1 - K) % 2 == 0:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = input()
	l = []
	x = 0
	for i in range(n):
		x ^= int(a[i])
		l.append(x)
	c = 0
	ci = 0
	ll = 0
	for i in range(n):
		if l[i] == 0:
			c += 1
		if l[i] != ll:
			ll = l[i]
			ci += 1
	if l[n - 1] == 0 and k <= c:
		print('YES')
	elif ci % 2 == k % 2 and k <= ci:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	ones = 0
	zeros = 0
	xor = 0
	for i in s:
		if i == '1':
			xor ^= 1
		if xor == 0:
			zeros += 1
		if xor != ones % 2:
			ones += 1
	if xor == 0 and zeros >= k or (ones >= k and ones % 2 == k % 2):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	p = list(map(int, input().split()))
	n = p[0]
	k = p[1]
	s = input()
	count0 = 0
	count1 = 0
	f = 0
	res = 0
	for x in s:
		res ^= ord(x) - 48
		if res == 0:
			count0 += 1
	if count0 >= k and res != 1:
		f = 1
		print('YES')
	res = 0
	for x in s:
		res ^= ord(x) - 48
		if res == 1:
			count1 += 1
			res = 0
	if count1 >= k and (count1 - k) % 2 == 0:
		if f != 1:
			f = 1
			print('YES')
	if f == 0:
		print('NO')


t = input()
for i in range(int(t)):
	(n, k) = map(int, input().split())
	s = input()
	x = 0
	j = 0
	zeros = 0
	ones = 0
	while j < n and zeros < k - 1:
		x ^= int(s[j])
		j += 1
		if x == 0:
			zeros += 1
			x = 0
	x = 0
	z = 0
	while z < n and ones < k - 1:
		x ^= int(s[z])
		z += 1
		if x == 1:
			ones += 1
			x = 0
	flag = False
	xor = 0
	if zeros == k - 1 and j < n:
		for temp in s[j:]:
			xor ^= int(temp)
		if xor == 0:
			flag = True
	xor = 0
	if ones == k - 1 and z < n:
		for temp in s[z:]:
			xor ^= int(temp)
		if xor == 1:
			flag = True
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	count = 0
	u = 0
	for i in range(n):
		u = u ^ int(s[i])
		if u == 0:
			count += 1
	v = 0
	count2 = 0
	for i in range(n):
		if s[i] == '1' and count2 != k:
			count2 += 1
		elif count2 == k:
			v ^= int(s[i])
	if count >= k and u == 0:
		print('YES')
	elif v == 0 and count2 == k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	(x, c1) = (0, 0)
	for i in s:
		x ^= int(i)
		if x == 0:
			c1 += 1
	if c1 >= k and x != 1:
		print('YES')
	else:
		(y, c2) = (0, 0)
		for i in s:
			y ^= int(i)
			if y == 1:
				c2 += 1
				y = 0
		if c2 >= k and (c2 - k) % 2 == 0:
			print('YES')
		else:
			print('NO')


from sys import stdin
input = stdin.readline
ans = {True: 'YES', False: 'NO'}

def can_split(S, K):
	N = len(S)
	ones = S.count('1')
	if ones == 0:
		return ans[K <= N]
	elif 1 == ones % 2:
		return ans[1 == K % 2 and ones >= K]
	elif 0 == K % 2 and ones >= K:
		return 'YES'
	else:
		divs = sum((len(ss) for ss in S.split('1')[::2])) + ones // 2
		return ans[divs >= K]
T = int(input())
for tx in range(T):
	(N, K) = map(int, input().split())
	S = input().strip()
	print(can_split(S, K))


ans = {True: 'YES', False: 'NO'}

def can_split(S, K):
	N = len(S)
	ones = S.count('1')
	if ones == 0:
		return ans[K <= N]
	elif 1 == ones % 2:
		return ans[1 == K % 2 and ones >= K]
	elif 0 == K % 2 and ones >= K:
		return 'YES'
	else:
		inpair = False
		for c in S:
			if c == '1':
				if inpair:
					K -= 1
				inpair = not inpair
			elif not inpair:
				K -= 1
			if K == 0:
				return 'YES'
		return 'NO'
T = int(input())
for tx in range(T):
	(N, K) = map(int, input().split())
	S = input().strip()
	print(can_split(S, K))


import sys
import math
from collections import defaultdict, Counter, deque
from bisect import *
from string import ascii_lowercase
from heapq import *

def readInts():
	x = list(map(int, sys.stdin.readline().rstrip().split()))
	return x[0] if len(x) == 1 else x

def readList(type=int):
	x = sys.stdin.readline()
	x = list(map(type, x.rstrip('\n\r').split()))
	return x

def readStr():
	x = sys.stdin.readline().rstrip('\r\n')
	return x
write = sys.stdout.write
read = sys.stdin.readline

def dist(x1, x2, y1, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def mergeSort(arr, check=lambda a, b: a < b, reverse=False):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L, check, reverse)
		mergeSort(R, check, reverse)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if check(L[i], R[j]):
				if not reverse:
					arr[k] = L[i]
					i += 1
				else:
					arr[k] = R[j]
					j += 1
			elif not reverse:
				arr[k] = R[j]
				j += 1
			else:
				arr[k] = L[i]
				i += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def maxSum(arr):
	max_sum = float('-inf')
	max_cur = 0
	for num in ar:
		max_cur = max(max_cur + num, num)
		if max_cur > max_sum:
			max_sum = max_cur
	return max_sum

def hcf(a, b):
	if b == 0:
		return a
	else:
		return hcf(b, b % a)

def get_power(n, m):
	i = 1
	p = -1
	while i <= n:
		i = i * m
		p += 1
	return p

def fact(n):
	f = 1
	for i in range(2, n + 1):
		f *= i
	return f

def solve(t):
	(n, k) = readInts()
	s = readStr()
	o_cnt = 0
	for c in s:
		if c == '1':
			o_cnt += 1
	if o_cnt == k:
		print('YES')
	else:
		cnt = 0
		i = 0
		b = False
		for i in range(n - 1):
			if cnt == k - 1:
				break
			if s[i] == '0':
				if not b:
					cnt += 1
			elif b:
				cnt += 1
				b = False
			else:
				b = True
		else:
			i += 1
		temp = 0
		while i < n:
			if s[i] == '1':
				temp += 1
			i += 1
		if temp % 2 == 0 and cnt == k - 1:
			print('YES')
		elif o_cnt >= k and (not o_cnt - k & 1):
			print('YES')
		else:
			print('NO')

def main():
	sys.setrecursionlimit(12000)
	t = readInts()
	for i in range(t):
		solve(i + 1)
main()


t = int(input())
for _ in range(0, t):
	inputs = [int(num) for num in input().split()]
	n = inputs[0]
	k = inputs[1]
	s = input()
	ones = 0
	zeros = 0
	for i in range(0, len(s)):
		if s[i] == '0':
			zeros += 1
		else:
			ones += 1
	if k % 2 == 1:
		min1 = 1
		max1 = 0
		c = 0
		onec = 0
		if ones % 2 == 0:
			i = 0
			while i < len(s):
				if s[i] == '0':
					if onec == 0:
						c += 1
				else:
					onec += 1
					if onec == 2:
						c += 1
						onec = 0
				i += 1
			max1 = c
			if k >= min1 and k <= max1:
				print('YES')
			else:
				print('NO')
		else:
			i = 0
			max1 = ones
			min1 = 1
			if k <= max1:
				print('YES')
			else:
				print('NO')
	elif ones % 2 == 1:
		print('NO')
	else:
		maxo = ones
		min1 = 1
		maxe = 0
		onec = 0
		c = 0
		i = 0
		while i < len(s):
			if s[i] == '0':
				if onec == 0:
					c += 1
			else:
				onec += 1
				if onec == 2:
					c += 1
					onec = 0
			i += 1
		maxe = c
		if k <= maxe or k <= maxo:
			print('YES')
		else:
			print('NO')


def cal_xor(c: int):
	z = K
	flag = xor = 0
	for i in range(N):
		xor ^= int(s[i])
		if z == 1:
			flag = 1
			z -= 1
		if not flag and xor == c:
			z -= 1
			xor = 0
	if xor == c and z == 0:
		return 1
	return 0

def calculate():
	a = cal_xor(0)
	b = cal_xor(1)
	return 'YES' if a or b else 'NO'
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	s = input()
	print(calculate())


def f():
	(x, c) = (0, 0)
	for i in range(n):
		x ^= l[i] == '1'
		if x == 1 and c < k - 1 and (i != n - 1):
			c += 1
			x = 0
	if c == k - 1 and x == 1:
		return 'YES'
	(x, c) = (0, 0)
	for i in range(n):
		x ^= l[i] == '1'
		if x == 0 and c < k - 1 and (i != n - 1):
			c += 1
			x = 0
	if c == k - 1 and x == 0:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = input()
	print(f())


def zxor(k):
	c = 0
	pos = 0
	while k > 0 and pos < n:
		if s[pos] == '1':
			c += 1
		elif c == 0:
			k -= 1
		if c == 2:
			k -= 1
			c = 0
		pos += 1
		if k == 0:
			break
	c = 0
	if k > 0:
		return False
	for j in range(pos, n):
		if s[j] == '1':
			c += 1
	return c % 2 == 0
for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	c1 = s.count('1')
	if zxor(k) or (c1 - k >= 0 and (c1 - k) % 2 == 0):
		print('YES')
	else:
		print('NO')


for T in range(int(input())):
	(N, K) = map(int, input().split())
	S = input()
	ZeroCount = 0
	ZP = False
	OneCount = 0
	prev = ' '
	for ch in S:
		if prev == ' ' and ch == '0':
			ZeroCount += 1
			prev = '0'
		elif prev == ' ' and ch == '1':
			prev = '1'
		elif prev == '0' and ch == '0':
			ZeroCount += 1
		elif prev == '0' and ch == '1':
			prev = '1'
		elif prev == '1' and ch == '0':
			pass
		elif prev == '1' and ch == '1':
			ZeroCount += 1
			prev = '0'
	if prev == '0':
		ZP = True
	for ch in S:
		if ch == '1':
			OneCount += 1
	if ZP and ZeroCount >= K:
		print('YES')
	elif OneCount >= K and (OneCount - K) % 2 == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	one = s.count('1')
	if one >= k:
		count = 0
		for i in range(n):
			if s[i] == '1':
				count += 1
			if count == k:
				break
		if count == k and one - k & 1 == 0:
			print('YES')
			continue
	count = 0
	i = 0
	while i < n:
		if s[i] == '0':
			count += 1
		elif s[i] == '1':
			i += 1
			while i < n and s[i] != '1':
				i += 1
			if i < n and s[i] == '1':
				count += 1
		i += 1
		if count == k:
			break
	if count == k and one & 1 == 0:
		print('YES')
		continue
	print('NO')


import sys
f = sys.stdin
next(f)
for (k, s) in zip(f, f):
	k = int(k.split()[1])
	i = j = 0
	for x in s[:-1]:
		if x == '1':
			i += 1
		if i & 1 ^ 1:
			j += 1
	print('YNEOS'[max((i ^ k) & 1 ^ 1 and i, i & 1 ^ 1 and j) < k::2])


def count0(s, n):
	c = 0
	x = 0
	for i in s:
		if i == '0':
			if x == 0:
				c += 1
		elif x == 1:
			c += 1
			x = 0
		else:
			x = 1
	if x == 1:
		return 0
	return c

def count1(s):
	c = 0
	for i in s:
		if i == '1':
			c += 1
	if c == 0:
		return 0
	return c
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	s = input()
	ones = count1(s)
	zeros = count0(s, n)
	if zeros >= k:
		print('YES')
		continue
	d = ones - k
	if d >= 0 and d % 2 == 0:
		print('YES')
		continue
	print('NO')


import sys
import sys
f = sys.stdin
next(f)
for (n, s) in zip(f, f):
	(n, k) = map(int, n.split())
	i = q = 0
	for x in s[:-1]:
		if x == '0':
			if i & 1 == 0:
				q += 1
		else:
			i += 1
			if i & 1 == 0:
				q += 1
	print('YNEOS'[max((i ^ k) & 1 ^ 1 and i, i & 1 ^ 1 and q) < k::2])


from typing import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = str(input())
	even_subs = 0
	odd_subs = 0
	one = 0
	ok = 0
	c = Counter(s)
	for i in range(n):
		if s[i] == '1':
			odd_subs += 1
			if one:
				even_subs += 1
				one = 0
			else:
				one = 1
		if s[i] == '0' and (not one):
			even_subs += 1
	if even_subs >= k and c['1'] & 1 == 0:
		ok = 1
	while odd_subs >= 0:
		if odd_subs == k:
			ok = 1
			break
		odd_subs -= 2
	if ok:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	key = 0
	ct0 = 0
	flag = 0
	ct1 = s.count('1')
	solo = 0
	if n < k:
		print('NO')
	elif k == 1:
		print('YES')
	elif k == 2:
		if ct1 % 2 == 1:
			print('NO')
		else:
			print('YES')
	elif ct1 % 2 == 1:
		if k % 2 == 1 and k <= ct1:
			print('YES')
		else:
			print('NO')
	else:
		for i in s:
			if key == 0 and i == '0':
				ct0 += 1
			elif key == 1 and i == '1':
				key = 0
				ct0 += 1
			elif key == 0 and i == '1':
				key = 1
		if k <= ct0:
			print('YES')
		elif k <= ct1 and k % 2 == 0:
			print('YES')
		else:
			print('NO')


from itertools import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	z = s.count('0')
	o = n - z
	s1 = 'NO'
	if k == 1 or (k == n and o in [0, n]):
		s1 = 'YES'
	elif k <= o and (o - k) % 2 == 0:
		s1 = 'YES'
	else:
		x = 0
		co = 0
		for i in s:
			x = x ^ int(i)
			if x == 0:
				co += 1
		if x == 0 and co >= k:
			s1 = 'YES'
	print(s1)


__author__ = 'nograhol'

def even_substr_max(S):
	st = 0
	ans = 0
	for i in range(len(S)):
		if st == 0 and S[i] == '0':
			ans += 1
		elif st == 0 and S[i] == '1':
			st = 1
		elif st == 1 and S[i] == '1':
			st = 0
			ans += 1
	return ans
T = int(input())
for ta in range(T):
	(N, K) = map(int, input().split(' '))
	S = input()
	ones = S.count('1')
	even = even_substr_max(S)
	if K <= even and ones % 2 == 0:
		print('YES')
	elif K <= ones and K % 2 == ones % 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	if k == 1:
		print('YES')
	else:
		ones = s.count('1')
		zeroes = len(s) - ones
		if ones % 2 == 1:
			if k % 2 == 1 and k <= ones:
				print('YES')
				continue
		elif k % 2 == 0 and k <= ones:
			print('YES')
			continue
		else:
			count = 0
			ans = 0
			for i in range(len(s)):
				if s[i] == '1':
					count += 1
				if count % 2 == 0:
					ans += 1
			if k <= ans:
				print('YES')
				continue
		print('NO')


from bisect import bisect_left
from re import sub
from typing import DefaultDict
import math
from collections import defaultdict
from math import sqrt
import collections
from sys import maxsize
from itertools import combinations_with_replacement
import sys

def sieve_erasthones(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	for p in range(n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def calculate(p, q):
	mod = 998244353
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def count_factors(n):
	i = 1
	c = 0
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				c += 1
			else:
				c += 2
		i += 1
	return c

def ncr_modulo(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def isprime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
		if prime_flag == 0:
			return True
		else:
			return False
	else:
		return True

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def dict_ele_count(l):
	d = DefaultDict(lambda : 0)
	for ele in l:
		d[ele] += 1
	return d

def max_in_dict(d):
	maxi = 0
	for ele in d:
		if d[ele] > maxi:
			maxi = d[ele]
	return maxi

def element_count(s):
	l = []
	k = s[0]
	c = 0
	for ele in s:
		if ele == k:
			c += 1
		else:
			l.append([k, c])
			k = ele
			c = 1
	l.append([k, c])
	return l

def modular_exponentiation(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 != 0:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def number_of_primefactor(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return len(set(l))

def twosum(a, n, x):
	rem = []
	for i in range(x):
		rem.append(0)
	for i in range(n):
		if a[i] < x:
			rem[a[i] % x] += 1
	for i in range(1, x // 2):
		if rem[i] > 0 and rem[x - i] > 0:
			return True
	if i >= x // 2:
		if x % 2 == 0:
			if rem[x // 2] > 1:
				return True
			else:
				return False
		elif rem[x // 2] > 0 and rem[x - x // 2] > 0:
			return True
		else:
			return False

def divSum(num):
	result = 0
	i = 2
	while i <= math.sqrt(num):
		if num % i == 0:
			if i == num / i:
				result = result + i
			else:
				result = result + (i + num / i)
		i = i + 1
	return result + 1 + num

def subsequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def solve():
	(n, k) = map(int, input().split())
	s = input()
	c1 = s.count('1')
	if c1 == 0:
		return 'YES'
	if c1 % 2 == 0:
		temp = []
		for i in range(n):
			if s[i] == '1':
				temp.append(i)
		ans = len(temp) // 2
		ans += temp[0]
		ans += n - temp[-1] - 1
		for i in range(2, len(temp), 2):
			ans += temp[i] - temp[i - 1] - 1
		if ans >= k:
			return 'YES'
	if c1 % 2 == k % 2 and c1 >= k:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
mod = 10 ** 4

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	ans = []
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count
from collections import defaultdict
import math

def primeFactors(n):
	res = set()
	while n % 2 == 0:
		res.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			res.add(i)
			n = n // i
	if n > 2:
		res.add(n)
	return res

def upper_bound(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans

def get_dis(s1, s2):
	s = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
	a1 = s.index(s1)
	a2 = s.rfind(s1)
	b1 = s.index(s2)
	b2 = s.rfind(s2)
	return min(abs(a1 - b1), abs(a1 - b2), abs(a2 - b1), abs(a2 - b2))
from collections import defaultdict

def func(l, m):
	ans = 0
	s = set()
	for ele in l:
		ans += ele % m
		print(ans, ele % m, ele, m)
		if ele % m in s:
			return -1
	print('tot', len(l) * (len(l) + 1) // 2, ans)
	if ans == len(l) * (len(l) + 1) // 2:
		return 1
	return 0

def printDivisors(n):
	i = 1
	res = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				res.append(i)
			else:
				res.append(i)
				res.append(n // i)
		i = i + 1
	return res

def func(x):
	c = 0
	while x != 0 and x % 2 == 0:
		x = x // 2
		c += 1
	return c
INF = 1000000000000000000000
from collections import deque

def solve():
	d = defaultdict(int)
	(n, k) = list(map(int, input().split()))
	s = input()
	c = s.count('1')
	if c & 1:
		if k & 1 and c >= k:
			print('YES')
		else:
			print('NO')
		return
	else:
		if c == k or (c >= k and c - k - 1 & 1):
			print('YES')
			return
		on = 0
		lst = []
		for (i, ele) in enumerate(s):
			if on == 0 and ele == '0':
				lst.append(i)
			elif on == 0 and ele == '1':
				on = 1
			elif on == 1 and ele == '1':
				on = 0
				lst.append(i)
		if len(lst) >= k:
			print('YES')
			return
	print('NO')
num_test = 1
num_test = int(input())
for _ in range(num_test):
	solve()


tc = int(input())
for _ in range(tc):
	(n, k) = map(int, input().split())
	s = input()
	ones = s.count('1')
	zeros = n - ones
	(yes, no) = ('YES', 'NO')
	if ones % 2 == 1:
		if k % 2 == 1 and ones >= k:
			print(yes)
		else:
			print(no)
	elif k % 2 == 0 and ones % 2 == 0 and (ones >= k):
		print(yes)
	else:
		(pairs, zs) = (0, 0)
		start = False
		for i in range(n):
			if s[i] == '1':
				if start:
					pairs += 1
					start = False
				else:
					start = True
			elif not start:
				zs += 1
		if pairs + zs >= k:
			print(yes)
		else:
			print(no)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k1 = k
	s = input()
	o = s.count('1')
	o1 = o
	p1 = 0
	while k1 > 0 and p1 < n:
		if s[p1] == '1':
			k1 -= 1
			o1 -= 1
		p1 += 1
	if k1 == 0 and o1 % 2 == 0:
		print('YES')
	else:
		p1 = 0
		co = 0
		while p1 < n and k > 0:
			if s[p1] == '0':
				if co == 0:
					k -= 1
			else:
				co += 1
				if co == 2:
					k -= 1
					o -= 2
					co = 0
			p1 += 1
		if k == 0 and o % 2 == 0:
			print('YES')
		else:
			print('NO')


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	s = input()
	x = 0
	for i in s:
		if i == '1':
			x += 1
	y = 0
	a = 0
	for i in s:
		if a == 0:
			if i == '0':
				y += 1
			else:
				a = 1 - a
		elif i != '0':
			a = 1 - a
			y += 1
	if X % 2 == 0:
		if x % 2 == 0:
			if x >= X:
				print('YES')
				continue
			elif y >= X:
				print('YES')
				continue
	else:
		if x % 2 == 1:
			if x >= X:
				print('YES')
				continue
		if x % 2 == 0:
			if y >= X:
				print('YES')
				continue
	print('NO')


import sys

def f(l, n, f):
	a = 0
	x = n - 1
	while a <= x:
		m = a + (x - a) // 2
		if l[m] == f:
			return m
		elif l[m] > f:
			x = m - 1
		else:
			a = m + 1
	return None
for _ in range(int(sys.stdin.readline())):
	(n, x) = map(int, sys.stdin.readline().split())
	s = input()
	c = s.count('1')
	j = 0
	k = 0
	t = 0
	for i in range(n):
		t = t ^ int(s[i])
		if t == 0:
			j = j + 1
	t = 0
	for i in range(n):
		t = t ^ int(s[i])
		if t == 1:
			k = k + 1
			t = 0
	if x % 2 == 0:
		if c % 2 == 1:
			print('NO')
		elif j >= x:
			print('YES')
		elif k >= x and (k - x) % 2 == 0:
			print('YES')
		else:
			print('NO')
	elif c % 2 == 1:
		if c >= x:
			print('YES')
		else:
			print('NO')
	elif j >= x:
		print('YES')
	elif k >= x and (k - x) % 2 == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	sum = 0
	x = True
	m = 0
	for i in s:
		if i == '1':
			sum += 1
			if sum % 2 == 1:
				x = False
			else:
				x = True
		if x:
			if i == '0':
				m += 1
	if k == 1:
		print('YES')
		continue
	if '1' not in s:
		print('YES')
		continue
	if sum % 2 == 0:
		if m + sum // 2 >= k:
			print('YES')
		elif k % 2 == 0:
			if k <= sum:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif k <= sum:
		if k % 2 == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin
input = stdin.readline

def solve(N, K, S):
	if K == 1:
		return 'YES'
	ones = sum((1 for s in S if s == '1'))
	if ones % 2 == 0:
		k = 0
		count = 0
		for i in range(N):
			if S[i] == '0' and count == 0:
				k += 1
			elif S[i] == '0' and count == 1:
				pass
			elif S[i] == '1' and count == 0:
				count = 1
			elif S[i] == '1' and count == 1:
				k += 1
				count = 0
		if k >= K:
			return 'YES'
	if ones >= K and (ones - K) % 2 == 0:
		return 'YES'
	return 'NO'
T = int(input().strip())
for problem in range(1, T + 1):
	(N, K) = [int(x) for x in input().strip().split()]
	S = input().strip()
	print(solve(N, K, S))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	o = 0
	z = 0
	for i in range(n):
		if s[i] == '1':
			o += 1
		else:
			z += 1
	if o % 2 == 0 and o // 2 + z >= k:
		c = 0
		cur = 0
		flag = 0
		for i in range(n):
			if s[i] == '0' and cur == 0:
				c += 1
			elif s[i] == '1' and cur == 0:
				cur = 1
			elif s[i] == '1' and cur == 1:
				cur = 0
				c += 1
		if c >= k and cur == 0:
			print('YES')
			continue
	if o % 2 == 0:
		x = o - k
		if x >= 0 and x % 2 == 0:
			print('YES')
			continue
		else:
			print('NO')
			continue
	if o % 2 != 0:
		x = o - k
		if x >= 0 and x % 2 == 0:
			print('YES')
			continue
		else:
			print('NO')
			continue


import sys
from collections import defaultdict, deque
from bisect import bisect_left
import math
input = sys.stdin.readline

def inp():
	l = list(map(int, input().split()))
	return l
for _ in range(int(input())):
	(n, k) = inp()
	s = list(input().strip())
	if k == 1:
		print('YES')
	else:
		for i in range(n):
			s[i] = int(s[i])
		x = 0
		xor = 0
		f = 0
		lu = -1
		for i in range(n):
			xor ^= s[i]
			if xor == x:
				lu = i
				f += 1
				xor = 0
		else:
			if lu != n - 1:
				f = -float('inf')
		g = 0
		x = 1
		xor = 0
		lu = -1
		for i in range(n):
			xor ^= s[i]
			if xor == x:
				lu = i
				g += 1
				xor = 0
		else:
			if lu != n - 1:
				for i in range(lu + 1, n):
					if s[i] != 0:
						g = -float('inf')
						break
		if f >= k:
			print('YES')
		elif g >= k:
			if (g - k) % 2 == 0:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	e = 0
	ind = 0
	c = 0
	h = 0
	lst1 = []
	while True:
		if ind > n - 1 or h == k - 1:
			break
		else:
			if s[ind] == '1':
				c += 1
			if c % 2 == 0:
				c = 0
				h += 1
			ind += 1
	co = s[ind:].count('1')
	if co % 2 == 0 and h == k - 1 and (s[ind:] != ''):
		print('YES')
	else:
		e = 0
		ind = 0
		c = 0
		h = 0
		lst1 = []
		while True:
			if ind > n - 1 or h == k - 1:
				break
			else:
				if s[ind] == '1':
					c += 1
				if c % 2 != 0:
					c = 0
					h += 1
				ind += 1
		co = s[ind:].count('1')
		if co % 2 != 0 and h == k - 1 and (s[ind:] != ''):
			print('YES')
		else:
			print('NO')


def solve(N, K, S):
	count0 = 0
	count1 = 0
	if len(S) < K:
		print('NO')
		return
	if K == 1:
		print('YES')
		return
	found0 = 0
	found1 = 0
	count1 = 0
	i = 0
	while i < len(S):
		if S[i] == '0':
			found0 += 1
			i += 1
		else:
			i += 1
			count1 += 1
			while i < len(S) and S[i] != '1':
				i += 1
			if i < len(S):
				found1 += 1
				count1 += 1
			i += 1
	if found0 + found1 >= K:
		if count1 == 0:
			print('YES')
			return
		elif count1 % 2 == 0:
			print('YES')
			return
	found0 = 0
	found1 = 0
	i = 0
	while i < len(S):
		if S[i] == '0':
			i += 1
		else:
			found1 += 1
			i += 1
	if found1 >= K and (found1 - K) % 2 == 0:
		print('YES')
		return
	print('NO')
	return
T = int(input())
res = []
for i in range(T):
	s = input().split()
	N = int(s[0])
	K = int(s[1])
	S = input()
	solve(N, K, S)


ans = ''
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	s = input()
	evenSub = 0
	oddSub = 0
	cnt1 = 0
	cnt2 = 0
	oneCount = 0
	for i in range(n):
		if s[i] == '1':
			oneCount += 1
			cnt1 += 1
			cnt2 += 1
		if cnt1 % 2 == 0:
			evenSub += 1
			cnt1 = 0
		if cnt2 % 2 == 1:
			oddSub += 1
			cnt2 = 0
	if oneCount % 2 == 0 and evenSub >= k:
		ans += 'YES\n'
	elif oddSub >= k and oddSub % 2 == k % 2:
		ans += 'YES\n'
	else:
		ans += 'NO\n'
print(ans)


from math import inf
from collections import *
import math, os, sys, heapq, bisect, random, threading
from functools import lru_cache
from itertools import *

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def inpu():
	return int(inp())

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())
(M, M1) = (1000000007, 998244353)

def main():
	how_much_noob_I_am = 1
	how_much_noob_I_am = inpu()
	for _ in range(how_much_noob_I_am):
		(n, k) = sep()
		s = inp()
		if k == 1:
			print('YES')
			continue
		xo = [0, 1]
		for xor in xo:
			p = 0
			res = 0
			for j in range(n):
				p ^= int(s[j])
				if p == xor:
					res += 1
					p = 0
					if res == k - 1:
						break
			if res == k - 1 and j + 1 < len(s):
				t = int(s[j + 1])
				for kk in range(j + 2, len(s)):
					t ^= int(s[kk])
				if t == xor:
					print('YES')
					break
		else:
			print('NO')
main()


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	s = input()
	n1 = s.count('1')
	c1 = n1 + 0
	g = k + 0
	if k <= n1:
		c1 = c1 - k + 1
		if c1 % 2 == 1:
			print('YES')
			continue
	if n1 % 2 == 1:
		pass
	else:
		twis = 0
		cont = 0
		for i in range(n):
			if s[i] == '1':
				if twis == 1:
					cont += 1
					twis = 0
					continue
				if twis == 0:
					twis = 1
			elif twis == 0:
				cont += 1
		if cont >= k:
			print('YES')
			continue
	print('NO')


def ispos(s, k):
	ss = ''
	xor = 0
	for i in s:
		xor ^= int(i)
		ss += str(xor)
	s = ss
	if s[-1] == '0' and s.count('0') >= k or k == 1:
		return 'YES'
	else:
		if k % 2 == 0 and 1 == int(s[-1]):
			return 'NO'
		elif k % 2 == 1 and 0 == int(s[-1]):
			return 'NO'
		st = 1
		i = k - 1
		for j in s[:-1]:
			if int(j) == st:
				i -= 1
				st ^= 1
			if i == 0:
				return 'YES'
		if i == 0:
			return 'YES'
		return 'NO'
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	print(ispos(input(), x))


from math import *
from collections import *
import os
from io import BytesIO, IOBase
import sys
from bisect import *
from heapq import *
MOD = 1000000007

def subinp():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('op1.txt', 'w')

def subinp_1():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('op2.txt', 'w')

def binpow(a, b, m):
	a %= m
	x = 1
	while b > 0:
		if b & 1:
			x = x * a % m
		a = a * a % m
		b >>= 1
	return x

def binser(arr, l, r, x):
	while l < r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return mid

def lcm(a, b):
	return a * b // gcd(a, b)

def sod(n):
	l = list(str(n))
	s = 0
	for i in l:
		s += int(i)
	return s

def prime_factors(num):
	l = []
	if num % 2:
		l.append(2)
	while num % 2 == 0:
		num = num / 2
	for i in range(3, int(sqrt(num)) + 1, 2):
		if not num % i:
			l.append(i)
		while num % i == 0:
			num = num / i
	if num > 2:
		l.append(num)
	return l

def factmod(n, p):
	f = defaultdict(int)
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % MOD
	return f

def largestPower(n, p):
	x = 0
	while n:
		n //= p
		x += n
	return x

def modFact(n, p):
	if n >= p:
		return 0
	res = 1
	isPrime = [1] * (n + 1)
	i = 2
	while i * i <= n:
		if isPrime[i]:
			for j in range(2 * i, n, i):
				isPrime[j] = 0
		i += 1
	for i in range(2, n):
		if isPrime[i]:
			k = largestPower(n, i)
			res = res * binpow(i, k, p) % p
	return res

def drec(x, y):
	if y == x + 1:
		return 'R'
	if y == x - 1:
		return 'L'
	if x < y:
		return 'D'
	return 'U'

def cellhash(x, y):
	return (x - 1) * m + y

def bins(l, x, n):
	i = bisect_left(l, x)
	if i < n:
		return i
	if i:
		return i - 1
	else:
		return n

def cond(l):
	for i in range(len(l) - 1):
		if l[i] == str(int(l[i + 1]) - 1):
			return False
	return True

def isvowel(s):
	if s in list('aeiou'):
		return 1
	return 0

def countOdd(L, R):
	N = (R - L) // 2
	if R % 2 != 0 or L % 2 != 0:
		N += 1
	return N

def tst(A, B, C):
	return (A | B) & (B | C) & (C | A)

def palcheck(n, s):
	(i, j) = (0, n - 1)
	while i <= j:
		if s[i] == s[j]:
			return False
		i += 1
		j -= 1
	return True

def sakurajima(n):
	if n < 9:
		n = 10
	l = [0]
	for i in range(1, n + 1):
		if i % 2:
			l.append(i)
		else:
			l.append(2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if l[i] == i:
			for j in range(i * i, n + 1, i):
				if l[j] == j:
					l[j] = i
	return l

def getfact(x):
	ret = []
	d = defaultdict(int)
	while x != 1:
		ret.append(spf[x] ** (d[spf[x]] + 1))
		d[spf[x]] += 1
		x = x // spf[x]
	return ret

def prchck(n):
	l = [1] * (n + 1)
	l[1] = 0
	for i in range(2, n + 1):
		for j in range(2, int(sqrt(n)) + 1):
			if j % i == 0:
				l[j] = 1
	return l

def ispal(s, n):
	for i in range(n // 2):
		if s[i] != s[n - i - 1]:
			return False
	return True

def bfs(src, dest, ajl, vis):
	q = deque([src])
	vis[src] = True
	while q:
		i = q.popleft()
		if i == dest:
			return True
		for j in ajl[i]:
			if not vis[j]:
				vis[j] = True
				q.append(j)
	return False

def sieve(n):
	if n < 9:
		n = 10
	l = [1] * (n + 1)
	for i in range(2, int(n ** 0.5) + 1):
		if l[i]:
			for j in range(i ** 2, n + 1, i):
				if j % i == 0:
					l[j] = 0
	l[1] = 0
	return l

class DisjSet:

	def __init__(self, n):
		self.size = [1] * n
		self.parent = [i for i in range(n)]

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.size[xset] < self.size[yset]:
			self.parent[xset] = yset
			self.size[yset] += self.size[xset]
		else:
			self.parent[yset] = xset
			self.size[xset] += self.size[yset]

def dfs(i, ajl, vis, l, x):
	vis[i] = True
	l[i] = x
	for j in ajl[i]:
		if not vis[j]:
			dfs(j, ajl, vis, l, x)

def checkpo3(N):
	while N > 0:
		if N % 3 == 2:
			return False
		N //= 3
	return True

def sumofdig(n):
	ans = 0
	s = str(n)
	for i in s:
		ans += int(i)
	return ans

def convert(set):
	return [*set]
inp = lambda : int(input())
strin = lambda : input().strip()
strl = lambda : list(input().strip())
strlst = lambda : list(map(str, input().split()))
mult = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
lstin = lambda : list(map(int, input().strip().split()))
flush = lambda : stdout.flush()
stdpr = lambda x: stdout.write(str(x))

def panda(n, k, l):
	o = l.count('1')
	if not (o - k) % 2 and o >= k:
		return True
	if o % 2:
		return False
	cnt = 0
	stp = 0
	for i in range(n):
		if l[i] == '1':
			if not stp:
				stp += 1
			else:
				stp -= 1
				cnt += 1
		elif not stp:
			cnt += 1
	if cnt >= k:
		return True
	return False
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = 1
t = int(input())
for _ in range(t):
	(n, k) = mult()
	l = strl()
	ans1 = panda(n, k, l)
	if ans1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = [int(s) for s in input().split(' ')]
	s = input()
	a = [int(b) for b in s]
	val = 0
	cnt = 0
	for i in range(n):
		val ^= a[i]
		if val == 0:
			cnt += 1
			val = 0
	if val != 1 and cnt >= k:
		print('YES')
		continue
	cnt = s.count('1')
	if cnt % 2 != k % 2:
		print('NO')
		continue
	if cnt >= k:
		print('YES')
	else:
		print('NO')


import math
from collections import defaultdict
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	s = input()
	flag = False
	one = False
	tot = 0
	if s.count('1') % 2 == 0:
		for j in range(0, len(s)):
			if one == False:
				if s[j] == '0':
					tot += 1
				else:
					one = True
			elif s[j] == '0':
				pass
			else:
				one = False
				tot += 1
	if tot >= b:
		flag = True
	if s.count('1') >= b:
		if (s.count('1') - b) / 2 == (s.count('1') - b) // 2:
			flag = True
	if flag:
		print('YES')
	else:
		print('NO')


import sys, os.path
from tabnanny import check
if os.path.exists('input.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def calcxor(s):
	xor = 0
	for c in s:
		xor = xor ^ int(c)
	print(xor)

def checkXOR(s, k, target, ct):
	curr = int(s[0])
	for i in range(1, len(s)):
		if curr == target:
			k -= 1
			curr = None
		if k == 0:
			return True
		c = int(s[i])
		if curr is None:
			curr = 0
		curr = c ^ curr
	if curr == target:
		k -= 1
	return k <= 0

def solve(s, n, k):
	ct = s.count('1')
	if ct % 2 == 0:
		if checkXOR(s, k, 0, ct) or (k % 2 == 0 and checkXOR(s, k, 1, ct)):
			return 'YES'
		else:
			return 'NO'
	if k % 2 == 0:
		return 'NO'
	if checkXOR(s, k, 1, ct):
		return 'YES'
	else:
		return 'NO'

def main():
	sys.setrecursionlimit(10 ** 8)
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		s = input()
		result = solve(s, n, k)
		print(result)
main()


def solve():
	n = l[0]
	k = l[1]
	xor = 0
	for i in range(n):
		if k == 1:
			if i == n - 1:
				if s[i] == '1':
					print('YES')
					return
			elif x(s[i:]) == 1:
				print('YES')
				return
		xor ^= int(s[i])
		if xor == 1:
			xor = 0
			k -= 1
	xor = 0
	k = l[1]
	for i in range(n):
		if k == 1:
			if i == n - 1:
				if s[i] == '0':
					print('YES')
					return
			elif x(s[i:]) == 0:
				print('YES')
				return
		else:
			xor ^= int(s[i])
		if xor == 0:
			xor = 0
			k -= 1
	print('NO')

def x(s):
	r = 0
	for i in s:
		r ^= int(i)
	return r
t = int(input())
while t > 0:
	l = list(map(int, input().split()))
	s = input()
	solve()
	t -= 1


T = int(input())
for _ in range(T):
	(N, K) = [int(x) for x in input().split()]
	S = input()
	s = sum((c == '1' for c in S))
	if not K & 1 and s & 1:
		print('NO')
	elif K & 1:
		s = s & 1
		cnt = 0
		curr = 0
		works = False
		for c in S:
			curr += c == '1'
			if curr & 1 == s:
				curr = 0
				cnt += 1
				if cnt == K:
					works = True
					break
		if works:
			print('YES')
		else:
			print('NO')
	else:
		for s in [0, 1]:
			cnt = 0
			curr = 0
			works = False
			for c in S:
				curr += c == '1'
				if curr & 1 == s:
					curr = 0
					cnt += 1
					if cnt == K:
						works = True
						break
			if works:
				print('YES')
				break
		if not works:
			print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	ones = s.count('1')
	zeroes = s.count('0')
	t0 = 0
	i = 0
	summ = 0
	flag0 = 1
	while i < len(s):
		if (summ + int(s[i])) % 2 == 0:
			t0 += 1
			summ = 0
		else:
			summ += int(s[i])
		i += 1
	if summ % 2 != 0:
		flag0 = 0
	i = 0
	t1 = 0
	summ = 0
	flag1 = 1
	while i < len(s):
		if (summ + int(s[i])) % 2 == 1:
			t1 += 1
			summ = 0
		else:
			summ += int(s[i])
		i += 1
	if flag0 and t0 == k or (flag1 and t1 == k):
		print('YES')
	elif t0 < k and t1 < k:
		print('NO')
	elif flag0 and t0 > k or (flag1 and t1 > k and ((t1 - k) % 2 == 0)):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	cnt = [0, 0]
	a = 0
	b = 0
	for i in range(n):
		if s[i] == '1':
			a += 1
			b += 1
		if a == 1:
			cnt[0] += 1
			a = 0
		if s[i] == '0' and b % 2 == 0 or b == 2:
			cnt[1] += 1
			b = 0
	if k <= cnt[0] and (cnt[0] - k) % 2 == 0 or (k <= cnt[1] and b == 0):
		print('YES')
	else:
		print('NO')


import math
import bisect
import heapq
from math import gcd, floor, sqrt, log
from collections import defaultdict as ddc
from collections import Counter

def intin():
	return int(input())

def mapin():
	return map(int, input().split())

def strin():
	return input().split()
INF = 10 ** 20
mod = 1000000007

def exponentiation(bas, exp, mod=1000000007):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % mod
		bas = bas * bas % mod
		exp //= 2
	return t % mod

def MOD(p, q=1, mod=1000000007):
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def process(S, N, K):
	total = S[0]
	count = 1 - total
	for ele in S[1:]:
		total ^= ele
		if not total:
			count += 1
	if total == 0:
		temp = S.count(1)
		if count >= K:
			return 'YES'
		elif temp >= K:
			if not K % 2:
				return 'YES'
		return 'NO'
	else:
		temp = S.count(1)
		if temp >= K:
			if K % 2:
				return 'YES'
		return 'NO'

def main():
	for _ in range(int(input())):
		(N, K) = mapin()
		S = list(map(int, list(input())))
		print(process(S, N, K))
main()


def main():
	(n, k) = map(int, input().split())
	b = list(map(int, list(input())))
	if k == 1:
		return 'YES'
	one = 0
	for z in b:
		if z:
			one += 1
	if one % 2 and k % 2 == 0:
		return 'NO'
	if one % 2 and k % 2:
		if one >= k:
			return 'YES'
		return 'NO'
	if one % 2 == 0 and k % 2 == 0:
		if one >= k:
			return 'YES'
		mx = 0
		flag = False
		for z in b:
			if not z:
				if not flag:
					mx += 1
			elif not flag:
				mx += 1
				flag = True
			else:
				flag = False
		if mx >= k:
			return 'YES'
		return 'NO'
	if one % 2 == 0 and k % 2:
		mx = 0
		flag = False
		for z in b:
			if not z:
				if not flag:
					mx += 1
			elif not flag:
				mx += 1
				flag = True
			else:
				flag = False
		if mx >= k:
			return 'YES'
		return 'NO'
for _ in range(int(input())):
	print(main())


def count(s):
	n = len(s)
	i = 0
	ans = 0
	while i < n:
		if s[i] == '0':
			ans += 1
			i += 1
		else:
			i += 1
			while i < n and s[i] != '1':
				i += 1
			ans += 1
			i += 1
	return ans
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	s = input()
	c = s.count('1')
	if c % 2 != 0:
		if k % 2 == 0:
			print('NO')
		elif k <= c:
			print('YES')
		else:
			print('NO')
	else:
		c = s.count('1')
		if k % 2 == 0:
			if k <= c:
				print('YES')
			elif k <= count(s):
				print('YES')
			else:
				print('NO')
		elif k <= count(s):
			print('YES')
		else:
			print('NO')


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	binary_str = input()
	int_str = []
	arr = []
	cur = 0
	count = {0: 0, 1: 0}
	int_count = {0: 0, 1: 0}
	for c in binary_str:
		cur = int(c) ^ cur
		arr.append(cur)
		count[cur] += 1
		int_count[int(c)] += 1
	if arr[-1] == 0 and count[0] >= K:
		print('YES')
	elif (int_count[1] - K) % 2 == 0 and int_count[1] >= K:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input()))
	part = 0
	flag = 0
	i = 0
	while i < n:
		if l[i] == 1:
			part += 1
		if part == k - 1:
			i += 1
			break
		i += 1
	c = 0
	while i < n:
		if l[i] == 1:
			c += 1
		i += 1
	if c % 2:
		flag = 1
	i = 0
	part = 0
	f = 0
	while i < n:
		if l[i] == 1:
			f += 1
		if f % 2 == 0:
			part += 1
		if part == k - 1:
			i += 1
			break
		i += 1
	c = 0
	fl = 0
	while i < n:
		fl = 1
		if l[i] == 1:
			c += 1
		i += 1
	if c % 2 == 0 and fl:
		flag = 1
	if flag or k == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(input())
	if n == k:
		if s.count('1') == n or s.count('1') == 0:
			print('YES')
		else:
			print('NO')
	else:
		f = True
		if s.count('1') % 2:
			f = False
		else:
			c = 0
			t = 0
			for ch in s:
				if ch == '1':
					t += 1
				if t % 2 == 0:
					c += 1
					t = 0
			if c < k:
				f = False
		if f:
			print('YES')
		else:
			f = True
			if abs(s.count('1') - k) % 2:
				f = False
			else:
				c = 0
				t = 0
				for ch in s:
					if ch == '1':
						t += 1
					if t % 2:
						c += 1
						t = 0
				if c < k:
					f = False
			if f:
				print('YES')
			else:
				print('NO')


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = input()
	fl = 0
	now = 0
	tobe = 0
	k = x
	ind = -1
	for i in range(n):
		now ^= int(a[i])
		if tobe == now:
			k -= 1
			if k == 0:
				ind = i
				break
			try:
				now = 0
			except:
				pass
	if ind != -1:
		if ind == n:
			if k == 0:
				fl = 1
		else:
			now = ind + 1
			one = 0
			for i in range(ind + 1, n):
				if a[i] == '1':
					one += 1
			if one % 2 == 0:
				fl = 1
	now = 0
	tobe = 1
	k = x
	ind = -1
	for i in range(n):
		now ^= int(a[i])
		if tobe == now:
			k -= 1
			if k == 0:
				ind = i
				break
			try:
				now = 0
			except:
				pass
	if ind != -1:
		if ind == n:
			if k == 0:
				fl = 1
		else:
			now = ind + 1
			one = 0
			for i in range(ind + 1, n):
				if a[i] == '1':
					one += 1
			if one % 2 == 0:
				fl = 1
	if fl == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = input()
	zc = s.count('0')
	oc = s.count('1')
	ttl_xor = 0
	for i in s:
		ttl_xor ^= int(i)
	xor = 0
	count = 0
	for i in s:
		u = int(i)
		xor ^= u
		if xor == 0:
			count += 1
		if count == k:
			break
	if count < k:
		ans1 = False
	elif xor == ttl_xor:
		ans1 = True
	else:
		ans1 = False
	xorb = 0
	xor = 0
	count = 0
	for i in s:
		u = int(i)
		xor ^= u
		xorb ^= u
		if xor == 1:
			count += 1
			xor = 0
		if count == k:
			break
	if count < k:
		ans2 = False
	elif xorb == ttl_xor:
		ans2 = True
	else:
		ans2 = False
	if ans1 or ans2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = input()
	xor = [0 for i in range(n)]
	xor[0] = int(s[0])
	cnt = 0
	if s[0] == '0':
		cnt += 1
	for i in range(1, n):
		xor[i] = xor[i - 1] ^ int(s[i])
		if xor[i] == 0:
			cnt += 1
	if xor[-1] == 0:
		if cnt >= k:
			print('YES')
		else:
			cnt = 0
			b = 0
			for i in range(n - 1, -1, -1):
				if b == 0:
					if xor[i] == 0:
						cnt += 1
						b = 1
				elif xor[i] == 1:
					cnt += 1
					b = 0
			if k % 2 == 0 and cnt >= k:
				print('YES')
			else:
				print('NO')
	else:
		cnt = 0
		b = 1
		for i in range(n - 1, -1, -1):
			if b == 0:
				if xor[i] == 0:
					cnt += 1
					b = 1
			elif xor[i] == 1:
				cnt += 1
				b = 0
		if k % 2 != 0 and cnt >= k:
			print('YES')
		else:
			print('NO')