You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010...

Calculate the number of prefixes of $t$ with balance equal to $x$. The balance of some string $q$ is equal to $cnt_{0, q} - cnt_{1, q}$, where $cnt_{0, q}$ is the number of occurrences of 0 in $q$, and $cnt_{1, q}$ is the number of occurrences of 1 in $q$. The number of such prefixes can be infinite; if it is so, you must say that.

A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd".


-----Input-----

The first line contains the single integer $T$ ($1 \le T \le 100$) — the number of test cases.

Next $2T$ lines contain descriptions of test cases — two lines per test case. The first line contains two integers $n$ and $x$ ($1 \le n \le 10^5$, $-10^9 \le x \le 10^9$) — the length of string $s$ and the desired balance, respectively.

The second line contains the binary string $s$ ($|s| = n$, $s_i \in \{\text{0}, \text{1}\}$).

It's guaranteed that the total sum of $n$ doesn't exceed $10^5$.


-----Output-----

Print $T$ integers — one per test case. For each test case print the number of prefixes or $-1$ if there is an infinite number of such prefixes.


-----Example-----
Input
4
6 10
010010
5 3
10101
1 0
0
2 0
01

Output
3
0
1
-1



-----Note-----

In the first test case, there are 3 good prefixes of $t$: with length $28$, $30$ and $32$.

Difficulty: MEDIUM_HARD

Solutions:
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	y = s.count('0') - s.count('1')
	z = 0
	inf = False
	ans = 0
	if x == 0:
		ans = 1
	for i in s:
		z += (i == '0') - (i == '1')
		if y == 0 and z == x:
			inf = True
			print(-1)
			break
		if x - z == 0 or ((x - z) * y > 0 and (x - z) % y == 0):
			ans += 1
	if not inf:
		print(ans)


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	x = int(l[1])
	s = input()
	numof1 = 0
	numof0 = 0
	count = 0
	countoffull = 0
	for i in s:
		if i == '0':
			countoffull += 1
		else:
			countoffull -= 1
	ans = 0
	for i in range(n):
		if s[i] == '1':
			numof1 += 1
		else:
			numof0 += 1
		if countoffull == 0:
			if x == numof0 - numof1:
				ans = -1
				break
		elif (x - numof0 + numof1) % countoffull == 0 and (x - (numof0 - numof1)) // countoffull >= 0:
			ans += 1
	if x == 0 and ans != -1:
		ans += 1
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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

def main():
	for _ in range(ii()):
		(n, x) = mi()
		s = list(si())
		if x < 0:
			for i in range(n):
				if s[i] == '1':
					s[i] = '0'
				else:
					s[i] = '1'
			x *= -1
		z = s.count('0')
		o = s.count('1')
		d = z - o
		c = [0] * n
		zz = 0
		oo = 0
		for i in range(n):
			if s[i] == '0':
				zz += 1
			else:
				oo += 1
			c[i] = zz - oo
		f = 1
		for i in range(n - 1):
			if s[i] == s[i + 1]:
				f = 0
				break
		if d == 0:
			f = 0
			for i in range(n):
				if c[i] == x:
					f = 1
					break
			if f:
				print(-1)
				continue
		ans = 0
		if x == 0:
			ans += 1
		if d >= 0:
			for i in range(n):
				l = 0
				r = 10 ** 9
				while l < r:
					mid = (l + r + 1) // 2
					if mid * d + c[i] <= x:
						l = mid
					else:
						r = mid - 1
				if l * d + c[i] == x:
					ans += 1
		else:
			for i in range(n):
				l = 0
				r = 10 ** 9
				while l < r:
					mid = (l + r + 1) // 2
					if mid * d + c[i] < x:
						r = mid - 1
					else:
						l = mid
				if l * d + c[i] == x:
					ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
t = int(input())
for e in range(t):
	(n, x) = list(map(int, input().split()))
	dp = [0 for i in range(n + 1)]
	s = input()
	cur = 0
	for i in range(n):
		if s[i] == '0':
			cur += 1
		else:
			cur -= 1
		dp[i + 1] = cur
	if dp[-1] == 0:
		if min(dp) <= x <= max(dp):
			print(-1)
		else:
			print(0)
		continue
	cnt = 0
	for i in range(n):
		diff = x - dp[i]
		if diff * dp[-1] >= 0 and diff % dp[-1] == 0:
			cnt += 1
	print(cnt)


t = int(input())
for i in ' ' * t:
	(n, x) = map(int, input().split())
	s = input()
	L = [0]
	for i in s:
		if i == '0':
			L.append(L[-1] + 1)
		else:
			L.append(L[-1] - 1)
	L.pop(0)
	k = L[-1]
	c = 0
	if x == 0:
		c += 1
	if k > 0:
		for i in L:
			if i % k == x % k and i <= x:
				c += 1
		print(c)
	elif k < 0:
		for i in L:
			if i % k == x % k and i >= x:
				c += 1
		print(c)
	else:
		for i in L:
			if i == x:
				c = -1
		print(c)


t = int(input())
for i in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	n = L[0]
	x = L[1]
	L2 = n * [0]
	ch = input()
	y = 0
	for i in range(n):
		if ch[i] == '0':
			y += 1
		else:
			y -= 1
		L2[i] = y
	if L2[-1] == 0:
		nb = 0
		for i in range(n):
			if L2[i] == x:
				nb += 1
		if nb > 0:
			print(-1)
		else:
			print(0)
	else:
		nb = 0
		if L2[-1] * x > 0 and x % L2[-1] == 0 or x == 0:
			nb = 1
		for i in range(n - 1):
			if x == L2[i] or ((x - L2[i]) % L2[-1] == 0 and (x - L2[i]) * L2[-1] > 0):
				nb += 1
		print(nb)


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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for _ in range(int(input())):
	(n, x) = mi()
	a = list(input())
	b = [0] * n
	(oc, zc) = (0, 0)
	for i in range(n):
		if a[i] == '1':
			oc += 1
		else:
			zc += 1
		b[i] = zc - oc
	if b[-1] == 0:
		if x in b:
			print(-1)
		else:
			print(0)
	else:
		c = b[-1]
		ans = 0
		for i in range(n):
			if c != 0 and (b[i] - x) % c == 0 and ((x - b[i]) / c >= 0):
				ans += 1
		if x == 0:
			ans += 1
		print(ans)


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_right
import math
t = int(input())
from collections import Counter
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	pre = [0]
	cnt = 0
	ans = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
		else:
			cnt -= 1
		pre.append(cnt)
	var = pre[-1]
	if var == 0:
		if x in pre:
			print(-1)
		else:
			print(0)
	else:
		for i in range(n):
			if (x - pre[i]) % pre[-1] == 0 and (x - pre[i]) // pre[-1] >= 0:
				ans += 1
		print(ans)


def count_pref(string, X):
	bal = 0
	cnt = 0
	for c in string:
		if bal == X:
			cnt += 1
		if c == '1':
			bal -= 1
		else:
			bal += 1
	return cnt

def count_all(string, X, delta):
	bal = 0
	cnt = 0
	for c in string:
		if bal <= X and delta >= 0 or (bal >= X and delta <= 0):
			if abs(bal - X) % abs(delta) == 0:
				cnt += 1
		if c == '1':
			bal -= 1
		else:
			bal += 1
	return cnt
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	ones = s.count('1')
	zeros = n - ones
	if zeros == ones:
		if count_pref(s, x) != 0:
			print(-1)
		else:
			print(0)
	else:
		print(count_all(s, x, zeros - ones))


def solve(n, x, s):
	s = list(s)
	k = []
	v = 0
	for i in s:
		v += 1 if i == '0' else -1
		k.append(v)
	l = k[-1]
	t = 0
	if l == 0:
		if x in k:
			return -1
		elif x == 0:
			return 1
		else:
			return 0
	else:
		if x == 0:
			t += 1
		for i in k:
			if (l >= 0 and i <= x or (l <= 0 and i >= x)) and (x - i) % l == 0:
				t += 1
	return t

def main():
	for _ in range(int(input())):
		(n, x) = list(map(int, input().split()))
		s = input()
		print(solve(n, x, s))
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	cs = []
	z = 0
	o = 0
	for j in range(n):
		if s[j] == '1':
			o += 1
		else:
			z += 1
		cs.append(z - o)
	le = cs[-1]
	f = 0
	for j in cs:
		if le != 0:
			if (x - j) % le == 0 and (x - j) * le >= 0:
				f += 1
		elif x == j:
			f += 1
	if f > 0 and le == 0:
		print(-1)
	else:
		if x == 0:
			f += 1
		print(f)


t = int(input())
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	s = input()
	(one, zero, lol) = (0, 0, 0)
	if x == 0:
		lol = 1
	(l1, l2) = ([], [])
	for i in range(n):
		if s[i] == '1':
			one += 1
		else:
			zero += 1
		l1.append(one)
		l2.append(zero)
	gotcha = 0
	for i in range(n):
		p = l2[i] - l1[i]
		if one == zero:
			if x == p:
				gotcha += 1
		else:
			a = x - p
			a = a / (zero - one)
			if a == int(a) and a >= 0:
				gotcha += 1
	if gotcha > 0 and one == zero:
		print('-1')
	else:
		print(gotcha + lol)


import bisect
from sys import stdin
input = stdin.readline
for xoxo in range(1):
	for _ in range(int(input())):
		a = []
		(n, x) = map(int, input().split())
		s = input()
		zc = s.count('0')
		oc = s.count('1')
		for i in range(n):
			a.append(int(s[i]))
		b = []
		k = 0
		for i in range(n):
			if a[i] == 0:
				k += 1
			else:
				k -= 1
			b.append(k)
		if zc == oc:
			k = 0
			if b.count(x) == 0:
				ans = 0
			else:
				ans = -1
		else:
			k = zc - oc
			if k > 0:
				for i in range(n):
					if abs(x - b[i]) % k == 0 and x >= b[i]:
						b[i] = x
			else:
				for i in range(n):
					if abs(b[i] - x) % k == 0 and x <= b[i]:
						b[i] = x
			ans = b.count(x)
		if x == 0 and ans != -1:
			print(ans + 1)
		else:
			print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	num = list(input())
	balance = [0] * len(num)
	ans = 0
	s = 0
	for i in range(len(num)):
		if num[i] == '1':
			s -= 1
		else:
			s += 1
		balance[i] = s
	step = balance[-1]
	for i in range(len(balance)):
		if balance[i] == x:
			ans += 1
		elif balance[i] > x and step < 0 and ((balance[i] - x) % step == 0):
			ans += 1
		elif balance[i] < x and step > 0 and ((x - balance[i]) % step == 0):
			ans += 1
	if step == 0 and ans != 0:
		print(-1)
	else:
		if x == 0:
			ans += 1
		print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	ar = input()
	score = 0
	li = []
	for i in range(n):
		if ar[i] == '1':
			score -= 1
		else:
			score += 1
		li.append(score)
	ans = 0
	if x in li and score == 0:
		print(-1)
	else:
		if score == 0:
			ans += li.count(x)
		else:
			for i in range(n):
				if (x - li[i]) % score == 0 and (x - li[i]) // score >= 0:
					ans += 1
		if x == 0:
			ans += 1
		print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	d = []
	a = 0
	if x > 0:
		for i in s:
			if i == '0':
				a += 1
			else:
				a -= 1
			d.append(a)
	else:
		x *= -1
		for i in s:
			if i == '1':
				a += 1
			else:
				a -= 1
			d.append(a)
	if d[-1] == 0:
		if x in d:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		p = d[-1]
		if p > 0:
			for i in d:
				if x >= i:
					if (x - i) % p == 0:
						ans += 1
		else:
			for i in d:
				if x <= i:
					if (x - i) % p == 0:
						if (x - i) // p > -1:
							ans += 1
		if x == 0:
			ans += 1
		print(ans)


def solve(n, x, s):
	ss = [0] * n
	if s[0] == '0':
		ss[0] = 1
	else:
		ss[0] = -1
	for i in range(1, n):
		if s[i] == '0':
			ss[i] = ss[i - 1] + 1
		else:
			ss[i] = ss[i - 1] - 1
	cnts = {}
	for i in range(n):
		if ss[i] in cnts:
			cnts[ss[i]] += 1
		else:
			cnts[ss[i]] = 1
	if ss[-1] == 0:
		if x in cnts:
			return -1
		else:
			return 0
	ans = 0
	if x == 0:
		ans += 1
	for k in cnts.keys():
		if (x - k) % ss[-1] == 0 and (x - k) * ss[-1] >= 0:
			ans += cnts[k]
	return ans

def main():
	t = int(input())
	for _ in range(t):
		(n, x) = [int(i) for i in input().split()]
		s = input().strip()
		print(solve(n, x, s))
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	(n, x) = map(int, input().split())
	string1 = input()
	initialb = 0
	for s in range(n):
		if string1[s] == '0':
			initialb += 1
		else:
			initialb -= 1
	if initialb != 0:
		prefsum = []
		count = 0
		for s in range(n):
			if string1[s] == '0':
				count += 1
			else:
				count -= 1
			prefsum.append(count)
		answer = 0
		prefsum.sort()
		for s in range(n):
			if (x - prefsum[s]) % initialb == 0:
				if (x - prefsum[s]) // initialb >= 0:
					answer += 1
	else:
		prefsum = []
		count = 0
		for s in range(n):
			if string1[s] == '0':
				count += 1
			else:
				count -= 1
			prefsum.append(count)
		prefsum.sort()
		answer = 0
		for s in range(len(prefsum)):
			if prefsum[s] == x:
				answer += 1
	if initialb == 0 and answer > 0:
		print(-1)
	else:
		if x == 0:
			answer += 1
		print(answer)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	if s[0] == '1':
		a = [-1]
	else:
		a = [1]
	for i in range(1, n):
		if s[i] == '0':
			a.append(a[i - 1] + 1)
		else:
			a.append(a[i - 1] - 1)
	g = 0
	for i in range(n):
		if a[i] == x:
			g = 1
			break
	if g == 1 and a[n - 1] == 0:
		print(-1)
	elif a[n - 1] == 0:
		print(0)
	else:
		tot = 0
		if x == 0:
			tot = 1
		for i in range(n):
			if a[i] == x:
				tot += 1
			else:
				g = x - a[i]
				if g % a[n - 1] == 0 and g * a[n - 1] >= 0:
					tot += 1
		print(tot)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	string = input()
	diff = []
	count_0 = 0
	count_1 = 0
	for i in range(n):
		if string[i] == '0':
			count_0 += 1
		else:
			count_1 += 1
		diff.append(count_0 - count_1)
	period = diff[-1]
	ans = 0
	if x == 0:
		ans += 1
	if period == 0:
		if x in diff:
			ans = -1
	else:
		for i in range(n):
			if (x - diff[i]) / period >= 0 and (x - diff[i]) / period == int((x - diff[i]) / period):
				ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(a, x) = map(int, input().split())
	s = input().strip()
	A = []
	r = 0
	dd = 0
	for c in s:
		if c == '0':
			r += 1
		else:
			r -= 1
		if r == x:
			dd += 1
		A.append(r)
	l = A[-1]
	if l == 0:
		if dd:
			print(-1)
		else:
			print(0)
		continue
	rr = 0
	for a in A:
		(k, j) = divmod(x - a, l)
		if j == 0 and k >= 0:
			rr += 1
	print(rr + (x == 0))


import sys
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	count = 0
	balance = 0
	for i in range(n):
		if s[i] == '0':
			balance += 1
		else:
			balance -= 1
		if balance == x:
			count += 1
	if balance == 0:
		if count > 0:
			print(-1)
		else:
			print(0)
		continue
	else:
		count = 0
		total_balance = balance
		balance = 0
		for i in range(n):
			if (x - balance) % total_balance == 0 and (x - balance) // total_balance >= 0:
				count += 1
			if s[i] == '0':
				balance += 1
			else:
				balance -= 1
		print(count)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	str = input()
	pre = ans = int(0)
	sum = str.count('0') - str.count('1')
	if sum == 0:
		for ch in str:
			if pre == x:
				ans = -1
				break
			if ch == '0':
				pre = pre + 1
			else:
				pre = pre - 1
	else:
		for ch in str:
			if (x - pre) % sum == 0 and (x - pre) / sum >= 0:
				ans = ans + 1
			if ch == '0':
				pre = pre + 1
			else:
				pre = pre - 1
	print(ans)


t = int(input())

def int_map(c):
	return 1 if c == '0' else -1
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	s = list(map(int_map, input()))
	bal = [0] * n
	cnt = 1 if x == 0 else 0
	b = 0
	for i in range(n):
		b += s[i]
		bal[i] = b
		if bal[i] == x:
			cnt += 1
	if b == 0:
		if cnt > 0:
			cnt = -1
	else:
		for i in range(n):
			rest = x - bal[i]
			k = rest // b
			if rest % b == 0 and k > 0:
				cnt += 1
	print(cnt)


t = int(input())
while t > 0:
	diff = int(input().split(' ')[1])
	s = input()
	balance = []
	currbal = 0
	inc = 0
	for idx in s:
		if idx == '0':
			currbal += 1
			balance.append(currbal)
		else:
			currbal -= 1
			balance.append(currbal)
	inc = currbal
	ans = 0
	if diff == 0:
		ans += 1
	for idx in balance:
		if inc == 0:
			if idx == diff:
				ans += 1
		elif (diff - idx) % inc == 0 and (diff - idx) / inc >= 0:
			ans += 1
	if ans > 0 and inc == 0:
		print(-1)
	else:
		print(ans)
	t -= 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	(s, ans, d) = (input(), 0, {})
	for q in s:
		d[ans] = d.get(ans, 0) + 1
		ans += (q == '0') * 2 - 1
	if ans == 0:
		print(-(x in d))
	elif ans > 0:
		x -= (x - 100001) // ans * ans * (x > 100001)
		answer = q1 = 0
		while x - q1 > -100001:
			if x - q1 in d:
				answer += d[x - q1]
			q1 += ans
		print(answer)
	else:
		x += (-x - 100001) // -ans * -ans * (x < -100001)
		answer = q1 = 0
		while x - q1 < 100001:
			if x - q1 in d:
				answer += d[x - q1]
			q1 += ans
		print(answer)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, X) = getInts()
	S = [int(s) for s in input()]
	prefs = []
	curr = 0
	for s in S:
		if s:
			curr -= 1
		else:
			curr += 1
		prefs.append(curr)
	if prefs[-1] == 0:
		if X in prefs:
			return -1
		else:
			return 0
	ans = 0
	for i in range(N):
		if prefs[i] == X:
			ans += 1
		elif prefs[i] < X and prefs[-1] > 0 and ((X - prefs[i]) % prefs[-1] == 0):
			ans += 1
		elif prefs[i] > X and prefs[-1] < 0 and ((prefs[i] - X) % -prefs[-1] == 0):
			ans += 1
	return ans + 1 if not X else ans
for _ in range(getInt()):
	print(solve())


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	cnt = {}
	cnt['0'] = 0
	cnt['1'] = 0
	balance = []
	for ch in s:
		cnt[ch] += 1
		balance.append(cnt['0'] - cnt['1'])
	m = balance[n - 1]
	q = 0
	if m == 0:
		if x in balance:
			q = -1
		else:
			q = balance.count(x)
	else:
		for b in balance:
			k = (x - b) // m
			if k >= 0 and k * m + b == x:
				q += 1
	if x == 0 and q != -1:
		q += 1
	print(q)


t = int(input())
for q in range(t):
	(n, x) = map(int, input().split())
	s = input()
	c0 = 0
	c1 = 0
	d = [0]
	for i in range(n):
		if s[i] == '0':
			c0 += 1
		else:
			c1 += 1
		d.append(c0 - c1)
	if d[-1] == 0:
		if x in d:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		l = d[-1]
		for i in range(n):
			if (x - d[i]) % l == 0 and (x - d[i]) // l >= 0:
				ans += 1
		print(ans)


t = int(input())

def solve():
	(n, x) = map(int, input().split())
	s = str(input())
	sum = 0
	res = 0
	sum_pre = [0 for _ in range(n)]
	if x == 0:
		res += 1
	for i in range(n):
		if s[i] == '0':
			sum += 1
		else:
			sum -= 1
		if sum == x:
			res += 1
		sum_pre[i] = sum
	if sum == 0 and res > 0:
		return -1
	if sum == 0:
		return 0
	for i in range(n):
		if sum_pre[i] != x and (x - sum_pre[i]) % sum == 0 and ((x - sum_pre[i]) // sum > 0):
			res += 1
	return res
while t > 0:
	print(solve())
	t -= 1


for _ in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	s = input()
	arr = [0] * n
	if s[0] == '0':
		arr[0] = 1
	else:
		arr[0] = -1
	for i in range(1, n):
		if s[i] == '0':
			arr[i] = arr[i - 1] + 1
		else:
			arr[i] = arr[i - 1] - 1
	count = 0
	if arr[n - 1] == 0:
		b = False
		for f in arr:
			if f == x:
				b = True
				break
		if b:
			print(-1)
		else:
			print(0)
	else:
		for f in arr:
			if (x - f) % arr[n - 1] == 0:
				if (x - f) // arr[n - 1] >= 0:
					count += 1
		if x == 0:
			count += 1
		print(count)


t = int(input().strip())
for _ in range(t):
	(n, x) = map(int, input().strip().split())
	s = input().strip()
	(the_max, the_min, cur) = (-100010, 100010, 0)
	cost = dict()
	for (index, i) in enumerate(s, 1):
		if i == '1':
			cur -= 1
			if cur < the_min:
				the_min = cur
		else:
			cur += 1
			if cur > the_max:
				the_max = cur
		cost[index] = cur
	if cur == 0:
		if x == 0:
			print(-1)
		elif x > 0:
			if the_max >= x:
				print(-1)
			else:
				print(0)
		elif the_min <= x:
			print(-1)
		else:
			print(0)
	else:
		ans = 1 if x == 0 else 0
		for i in range(1, n + 1):
			re = x - cost[i]
			if re // cur >= 0 and re % cur == 0:
				ans += 1
		print(ans)


from collections import defaultdict

def balance_is_realizable(imbalance, x, balance):
	if imbalance >= 0:
		return x - balance >= 0
	else:
		return x - balance <= 0

def main():
	t = int(input())
	for i in range(t):
		(n, x) = tuple((int(o) for o in input().split()))
		string = input()
		balances_to_occurrences = defaultdict(int)
		imbalance = 0
		s = 0
		for char in string:
			if char == '0':
				imbalance += 1
			else:
				imbalance -= 1
			balances_to_occurrences[imbalance] += 1
		if imbalance == 0:
			if x in balances_to_occurrences or x == 0:
				print(-1)
			else:
				print(0)
		else:
			for (balance, occurrences) in balances_to_occurrences.items():
				if (x - balance) % imbalance == 0 and balance_is_realizable(imbalance, x, balance):
					s += occurrences
			if x == 0:
				s += 1
			print(s)
main()


import sys
from collections import defaultdict

def get(s, x):
	dic = defaultdict(int)
	bal = 0
	n = len(s)
	z = False
	for i in range(n):
		if s[i] == '1':
			bal -= 1
		else:
			bal += 1
		if bal == x:
			z = True
		dic[i] = bal
	if z and bal == 0:
		return -1
	if bal > 0:
		count = 0
		for i in dic:
			if x >= dic[i]:
				if (x - dic[i]) % bal == 0:
					count += 1
	if bal < 0:
		count = 0
		for i in dic:
			if x <= dic[i]:
				if abs(x - dic[i]) % abs(bal) == 0:
					count += 1
	if bal == 0:
		count = 0
		for i in dic:
			if dic[i] == x:
				return -1
	if x == 0:
		count += 1
	return count
t = int(sys.stdin.readline())
for _ in range(t):
	(n, x) = map(int, sys.stdin.readline().split())
	s = sys.stdin.readline()[:-1]
	print(get(s, x))


from collections import defaultdict as d
t = int(input())
for _ in range(t):
	(n, x) = [int(aa) for aa in input().split()]
	s = input()
	balanceCounts = d(lambda : 0)
	balanceCounts[0] += 1
	bal = 0
	for i in range(n):
		if s[i] == '1':
			bal -= 1
		else:
			bal += 1
		balanceCounts[bal] += 1
	balanceCounts[bal] -= 1
	if bal == 0:
		if balanceCounts[x] > 0:
			ans = -1
		else:
			ans = 0
	else:
		minBal = min(balanceCounts.keys())
		maxBal = max(balanceCounts.keys())
		aa = max(0, (x - minBal) // bal)
		bb = max(0, (x - maxBal) // bal)
		kLower = min(aa, bb)
		kUpper = 1 + max(aa, bb)
		ans = 0
		for k in range(kLower, kUpper + 1):
			intermediateBalance = x - k * bal
			ans += balanceCounts[intermediateBalance]
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = str(input())
	cnt = s.count('0') - s.count('1')
	bal = ans = 0
	for i in range(len(s)):
		if cnt == 0:
			if bal == x:
				ans = -1
				break
		elif abs(x - bal) % abs(cnt) == 0:
			if (x - bal) / cnt >= 0:
				ans += 1
		if s[i] == '0':
			bal += 1
		else:
			bal -= 1
	print(ans)


import sys
t = int(sys.stdin.readline())

def neg(s):
	ans = ['0'] * len(s)
	for (i, c) in enumerate(s):
		if c == '0':
			ans[i] = '1'
	return ans
for _ in range(t):
	(n, x) = [int(i) for i in sys.stdin.readline().split()]
	s = sys.stdin.readline().strip()
	at = 0
	if x < 0:
		x = -x
		s = neg(s)
	gain = len(list(filter(lambda c: c == '0', s))) - len(list(filter(lambda c: c == '1', s)))
	balance = 0
	ans = 0
	for c in s:
		if gain == 0:
			if balance == x:
				ans = -1
				break
		elif not (balance > x and gain > 0 or (balance < x and gain < 0)):
			if (balance - x) % gain == 0:
				ans += 1
		if c == '0':
			balance += 1
		else:
			balance -= 1
	print(ans)


t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	bs = str(input())
	pref = [0 for i in range(n)]
	for i in range(n):
		if i == 0:
			if bs[i] == '0':
				pref[i] = 1
			else:
				pref[i] = -1
		elif bs[i] == '0':
			pref[i] = pref[i - 1] + 1
		else:
			pref[i] = pref[i - 1] - 1
	ans = 0
	last = pref[-1]
	if k == 0:
		ans += 1
	if last != 0:
		for i in range(len(pref)):
			tt = (k - pref[i]) // last
			if tt == 0 and last == 0:
				ans = -1
				break
			if tt * last + pref[i] == k and tt >= 0:
				ans += 1
		print(ans)
	else:
		for i in range(len(pref)):
			if pref[i] == k:
				ans = -1
				break
		print(ans)
	t -= 1


T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	s = input()
	L = []
	c0 = 0
	c1 = 0
	for i in range(0, len(s)):
		if s[i] == '0':
			c0 += 1
		else:
			c1 += 1
		L.append(c0 - c1)
	diff = s.count('0') - s.count('1')
	if diff == 0:
		ans = 0
		if x == 0:
			ans += 1
		if x in L:
			print(-1)
		else:
			print(ans)
	else:
		ans = 0
		if x == 0:
			ans += 1
		for i in range(0, len(L)):
			if (x - L[i]) % diff == 0 and (x - L[i]) // diff + 1 > 0:
				ans += 1
		print(ans)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, X) = [int(x) for x in input().split()]
		S = input().strip()
		ans = 0
		ansa = []
		for s in S:
			if int(s) == 0:
				ans += 1
				ansa.append(ans)
			else:
				ans -= 1
				ansa.append(ans)
		if X in ansa and ansa[-1] == 0:
			print(-1)
		else:
			pans = 0
			if X == 0:
				pans += 1
			if ansa[-1] > 0:
				for a in ansa:
					if X - a >= 0 and (X - a) % ansa[-1] == 0:
						pans += 1
				print(pans)
			elif ansa[-1] < 0:
				for a in ansa:
					if a - X >= 0 and (a - X) % abs(ansa[-1]) == 0:
						pans += 1
				print(pans)
			else:
				for a in ansa:
					if a == X:
						pans += 1
				print(pans)
main()


def solve():
	(n, x) = map(int, input().split())
	s = input()
	q = [0]
	for (i, s_i) in enumerate(s):
		q.append(q[i] + (1 if s_i == '0' else -1))
	q = q[1:]
	sol = 1 if x == 0 else 0
	for i in q:
		if q[-1] == 0:
			if i == x:
				sol = -1
		else:
			need = x - i
			if need % q[-1] == 0 and need * q[-1] >= 0:
				sol += 1
	print(sol)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	diff = s.count('0') - s.count('1')
	(z, o, ans) = (0, 0, 0)
	if x == 0:
		ans = 1
	for c in s:
		if c == '0':
			z += 1
		else:
			o += 1
		k = x - z + o
		if k == 0 and diff == 0 or (diff != 0 and k % diff == 0 and (k // diff >= 0)):
			ans += 1
	if z == o and ans > 0:
		ans = -1
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	pref = [0]
	for i in range(n):
		pref.append(pref[-1] + 2 * (s[i] == '0') - 1)
	jump = pref.pop()
	if jump == 0:
		print(-1 * (min(pref) <= x <= max(pref)))
	else:
		tot = 0
		for delta in pref:
			if (x - delta) % jump == 0 and (x - delta) // jump >= 0:
				tot += 1
		print(tot)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	bal = [0] * (n + 1)
	for i in range(1, n + 1):
		if s[i - 1] == '0':
			bal[i] = bal[i - 1] + 1
		else:
			bal[i] = bal[i - 1] - 1
	mult = bal[-1]
	ans = 0
	if mult == 0:
		if x in bal[1:]:
			print(-1)
		else:
			print(0)
	else:
		for num in bal[1:]:
			if (x - num) % mult == 0 and (x - num) / mult >= 0:
				ans += 1
		if x == 0:
			ans += 1
		print(ans)


from math import *
from bisect import *
t = int(input())
for i in range(t):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	s = input()
	pre_arr = [0]
	for j in s:
		if j == '0':
			pre_arr.append(pre_arr[-1] + 1)
		else:
			pre_arr.append(pre_arr[-1] - 1)
	count_arr = []
	flag0 = False
	for j in range(1, n + 1):
		temp = x - pre_arr[j]
		if pre_arr[-1] == 0:
			if pre_arr[j] == x:
				flag0 = True
				break
		elif temp % pre_arr[-1] == 0 and temp * pre_arr[-1] >= 0:
			count_arr.append(1)
		else:
			count_arr.append(0)
	if flag0 == True:
		print(-1)
	else:
		ans = sum(count_arr)
		if x == 0:
			ans += 1
		print(ans)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	answer = 0
	bal = 0
	mass = [0] * n
	for j in range(n):
		if s[j] == '0':
			bal += 1
		else:
			bal -= 1
		mass[j] = bal
	if x == 0:
		answer += 1
	if bal == 0 and (max(mass) >= x and x >= 0 or (min(mass) <= x and x <= 0)):
		print(-1)
	elif bal == 0:
		print(0)
	else:
		for j in range(n):
			if mass[j] < x and bal < 0 or (mass[j] > x and bal > 0):
				continue
			if (x - mass[j]) % bal == 0:
				answer += 1
		print(answer)


nn = int(input())
for i in range(nn):
	(n, x) = [int(i) for i in input().split(' ')]
	s = input()
	k0 = s.count('0')
	k1 = s.count('1')
	if k0 - k1 == 0 and x == 0:
		print(-1)
		continue
	rez = 0
	if x == 0:
		rez = 1
	b = 0
	bal = []
	for j in range(n):
		if s[j] == '1':
			b -= 1
		else:
			b += 1
		bal.append(b)
	if s[0] == '1':
		b -= 1
	else:
		b += 1
	shag = b - bal[0]
	if shag != 0:
		for j in range(n):
			if (x - bal[j]) % shag == 0 and (bal[j] == x or abs(bal[j] + shag - x) <= abs(bal[j] - x)):
				rez += 1
	else:
		for j in range(n):
			if bal[j] == x:
				rez += 1
		if rez > 0:
			rez = -1
	print(rez)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	s = list(map(int, input()))
	bal = [0] * (n + 1)
	cnt = 1 if x == 0 else 0
	for i in range(n):
		if s[i] == 0:
			bal[i + 1] = bal[i] + 1
		else:
			bal[i + 1] = bal[i] - 1
		if bal[i + 1] == x:
			cnt += 1
	b = bal[-1]
	if b == 0 and cnt > 0:
		print(-1)
	elif b == 0 and cnt == 0:
		print(0)
	elif b != 0:
		for i in range(n):
			rest = x - bal[i + 1]
			k = rest // b
			if rest % b == 0 and k > 0:
				cnt += 1
		print(cnt)
	else:
		print(cnt)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	s = input()
	pre = [1]
	if s[0] == '1':
		pre[0] = -1
	for i in range(1, 2 * n):
		pre.append(pre[i - 1] + 1)
		if i >= n:
			i -= n
		if s[i] == '1':
			pre[-1] -= 2
	if pre[:n] == pre[n:]:
		if x in pre:
			print(-1)
		else:
			print(0)
	else:
		tot = 0
		if x == 0:
			tot += 1
		for i in range(n):
			if (x - pre[i]) % (pre[i + n] - pre[i]) == 0:
				if pre[i] < pre[i + n] and x < pre[i]:
					continue
				if pre[i] > pre[i + n] and x > pre[i]:
					continue
				tot += 1
		print(tot)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = input()
	bal = [0] * n
	balance = 0
	inf = False
	for i in range(n):
		bal[i] = balance
		if a[i] == '0':
			balance += 1
		else:
			balance -= 1
		if balance == x:
			inf = True
	tot = balance
	if tot == 0:
		if inf:
			print(-1)
		elif x == 0:
			print(1)
		else:
			print(0)
	else:
		ans = 0
		for i in range(n):
			if (x - bal[i]) / tot >= 0 and abs(x - bal[i]) % abs(tot) == 0:
				ans += 1
		print(ans)


import math
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	s = input()
	l = []
	z = 0
	o = 0
	for j in s:
		if j is '0':
			z += 1
		else:
			o += 1
		l.append(z - o)
	d = z - o
	if d == 0:
		res = math.inf if x in l else 0
	elif d > 0:
		res = sum((1 for i in l if x >= i and (x - i) % d == 0))
	else:
		res = sum((1 for i in l if x <= i and (i - x) % (-1 * d) == 0))
	if x == 0:
		res += 1
	print(-1 if res == math.inf else res)


T = int(input())
for i in range(T):
	(n, x) = map(int, input().split())
	s = [int(i) for i in input()]
	balanced = [0]
	for j in s:
		if j == 0:
			balanced.append(balanced[-1] + 1)
		else:
			balanced.append(balanced[-1] - 1)
	if balanced[-1] == 0:
		if x in balanced:
			print(-1)
		else:
			print(0)
	elif balanced[-1] < 0:
		ans = 0
		if x == 0:
			ans = 1
		for k in balanced[1:]:
			if k >= x and (x - k) % balanced[-1] == 0:
				ans += 1
		print(ans)
	else:
		ans = 0
		if x == 0:
			ans = 1
		for k in balanced[1:]:
			if k <= x and (x - k) % balanced[-1] == 0:
				ans += 1
		print(ans)


def calc(s, x):
	orig = [-1]
	if s[0] == '0':
		orig = [1]
	for i in range(1, len(s)):
		if s[i] == '0':
			orig.append(orig[-1] + 1)
		else:
			orig.append(orig[-1] - 1)
	(diff, cum) = ([], orig[-1])
	res = 0
	if x == 0:
		res = 1
	for i in range(len(s)):
		if orig[i] == x:
			res += 1
		if s[i] == '0':
			cum += 1
		else:
			cum -= 1
		diff = cum - orig[i]
		if diff == 0 and orig[i] == x:
			return -1
		elif diff == 0 and orig[i] != x:
			continue
		n = (x - orig[i]) / diff
		if n % 1 == 0 and n > 0:
			res += 1
	return res
N = int(input())
cases = []
for _ in range(N):
	(_, x) = map(int, input().split())
	s = input()
	cases.append([s, x])
for (s, x) in cases:
	print(calc(s, x))


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	a = ans = 0
	cnt = [0] * (2 * n + 1)
	cnt[n] = 1
	for i in range(n):
		if s[i] == '0':
			a += 1
		else:
			a -= 1
		cnt[a + n] += 1
	cnt[a + n] -= 1
	x += n
	if not a:
		if 0 <= x <= 2 * n:
			print([0, -1][cnt[x] > 0])
		else:
			print(0)
		continue
	if a > 0 and x > 2 * n or (a < 0 and x < 0):
		a = abs(a)
		x %= a
		while x <= 2 * n:
			ans += cnt[x]
			x += a
	else:
		while 0 <= x <= 2 * n:
			ans += cnt[x]
			x -= a
	print(ans)


T = int(input())
for _ in range(T):
	(n, x) = list(map(int, input().split(' ')))
	s = input()
	delta = 0
	diff_lst = []
	for c in s:
		if c == '0':
			delta += 1
		else:
			delta -= 1
		diff_lst.append(delta)
	count = 0
	if x == 0:
		count += 1
	for diff in diff_lst:
		if delta != 0:
			if (x - diff) % delta == 0 and (x - diff) // delta >= 0:
				count += 1
		elif x - diff == 0:
			count += 1
	if count != 0 and delta == 0:
		print('-1')
	else:
		print(count)


t = int(input())
for i in range(t):
	n_x = list(map(int, input().split(' ')))
	(n, x) = n_x
	pre = input()
	zero = 0
	ones = 0
	count = 0
	sett = set()
	diff = 0
	for i in pre:
		if i == '0':
			diff += 1
			sett.add(diff)
		else:
			diff -= 1
			sett.add(diff)
	if diff != 0 and x == 0:
		count += 1
	if diff == 0:
		if x in sett:
			print(-1)
		else:
			print(0)
	else:
		new_diff = 0
		for i in pre:
			if i == '0':
				new_diff += 1
			else:
				new_diff -= 1
			if diff < 0 and new_diff >= x and (abs(new_diff - x) % diff == 0):
				count += 1
			elif diff > 0 and new_diff <= x and (abs(new_diff - x) % diff == 0):
				count += 1
		print(count)


I = input
for _ in [0] * int(I()):
	x = int(I().split()[1])
	a = []
	s = 0
	for c in I():
		a += (x - s,)
		s += 1 - 2 * int(c)
	print(sum((y * s >= 0 == y % s for y in a)) if s else -(0 in a))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = 0
	c = {}
	for b in map(int, input()):
		if b:
			s -= 1
		else:
			s += 1
		c[s] = c.get(s, 0) + 1
	ans = 0
	if s:
		for (k, v) in c.items():
			if 0 == (m - k) % s:
				y = (m - k) // s
				if y >= 0:
					ans += v
		if not m:
			ans += 1
	else:
		ans = -1 if m in c else 0
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	b = list(input().strip())
	(cnt0, cnt1) = ([0], [0])
	(c0, c1) = (0, 0)
	for i in b:
		if i == '0':
			c0 += 1
			cnt0.append(cnt0[-1] + 1)
			cnt1.append(cnt1[-1])
		else:
			c1 += 1
			cnt0.append(cnt0[-1])
			cnt1.append(cnt1[-1] + 1)
	diff = []
	for i in range(n + 1):
		diff.append(cnt0[i] - cnt1[i])
	if diff[0] == diff[-1]:
		if x in diff:
			print(-1)
		else:
			print(0)
	else:
		k = 0
		inc = diff[-1]
		inv = []
		for i in diff[:-1]:
			inv.append(x - i)
		for i in inv:
			if i * inc >= 0 and i % inc == 0:
				k += 1
		print(k)


t = int(input())
for test in range(t):
	(n, x) = map(int, input().split())
	s = input()
	arr = []
	count = 0
	for i in range(n):
		if s[i] == '0':
			count += 1
		else:
			count -= 1
		arr.append(count)
	iflag = False
	if arr[n - 1] == 0:
		for i in arr:
			if i == x:
				iflag = True
	if iflag == True:
		print(-1)
		continue
	if arr[n - 1] == 0:
		print(0)
		continue
	al = arr[n - 1]
	cnt = 0
	for i in range(n):
		if (x - arr[i]) % al == 0:
			if (x - arr[i]) // al >= 0:
				cnt += 1
	if x == 0:
		cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().strip().split()))
	a = input()
	b = []
	s = 0
	for j in range(n):
		if a[j] == '0':
			s = s + 1
			b.append(s)
		else:
			s = s - 1
			b.append(s)
	c = 0
	e = 1
	for j in range(n):
		if b[n - 1] != 0:
			if (x - b[j]) % b[n - 1] == 0 and (x - b[j]) // b[n - 1] >= 0:
				c = c + 1
		if b[j] == x and b[n - 1] == 0:
			e = 0
	if x == 0:
		c = c + 1
	if e == 1:
		print(c)
	else:
		print(-1)


from collections import defaultdict
import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	(n, x) = map(int, input().split())
	S = list(input())
	S = list(map(int, S))
	D = defaultdict(int)
	d = 0
	for v in S:
		D[d] += 1
		if v == 0:
			d += 1
		else:
			d -= 1
	if d == 0:
		if D[x] > 0:
			print(-1)
		else:
			print(0)
		return
	else:
		ans = 0
		for (key, value) in D.items():
			if (x - key) % d == 0 and (x - key) // d >= 0:
				ans += value
		print(ans)
	return

def main():
	t = int(input())
	for i in range(t):
		slv()
	return
main()


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

def array():
	return list(map(int, input().split()))

def main():
	(n, m) = vars()
	s = input()
	pre = []
	z = 0
	o = 0
	for i in range(n):
		pre.append(z - o)
		if s[i] == '0':
			z += 1
		else:
			o += 1
	l = z - o
	if l == 0 and (m in pre or l == m):
		print(-1)
	elif l == 0:
		print(0)
	else:
		cnt = 0
		for i in range(len(pre)):
			p = m - pre[i]
			if p * l >= 0 and p % l == 0:
				cnt += 1
		print(cnt)
t = int(input())
for _ in range(t):
	main()


T = int(input())

def solve():
	[N, X] = list(map(int, input().split()))
	S = input()
	z_o_f = 0
	for c in S:
		if c == '0':
			z_o_f += 1
		else:
			z_o_f -= 1
	if z_o_f == 0 and X == 0:
		return -1
	ans = 0
	if X == 0:
		ans += 1
	z_o = 0
	for c in S:
		if c == '0':
			z_o += 1
		else:
			z_o -= 1
		if z_o_f == 0:
			if z_o == X:
				return -1
		elif (X - z_o) % z_o_f == 0 and (X - z_o) // z_o_f >= 0:
			ans += 1
	return ans
for _ in range(T):
	print(solve())


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(n, x) = mints()
	s = minp()
	p = 0
	all = dict()
	m = int(1000000000.0)
	M = int(-1000000000.0)
	for i in range(n):
		all[p] = all.get(p, 0) + 1
		m = min(m, p)
		M = max(M, p)
		if s[i] == '0':
			p += 1
		else:
			p -= 1
	if p == 0:
		if x in all:
			print(-1)
		else:
			print(0)
		return
	ss = 1
	if p < 0:
		p = -p
		(m, M) = (-M, -m)
		ss = -1
		x = -x
	do = max((x - M) // p, 0)
	r = 0
	while x - do * p >= m:
		y = ss * (x - p * do)
		if y in all:
			r += all[y]
		do += 1
	print(r)
for i in range(mint()):
	solve()


import sys, os, io
from collections import defaultdict
for _ in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	dic = defaultdict(lambda : 0)
	s = input()
	cnt = 0
	zero = 0
	mini = 10 ** 10
	maxi = -10 ** 10
	for i in s:
		if i == '0':
			cnt += 1
		else:
			cnt -= 1
		dic[cnt] += 1
		if cnt == 0:
			zero += 1
		mini = min(mini, cnt)
		maxi = max(maxi, cnt)
	last = 0
	if cnt == 0:
		if x in dic:
			print(-1)
		else:
			print(0)
	elif cnt > 0:
		ans = 0
		mm = (x - maxi) // cnt
		if mm > 0:
			mm -= 1
			last = mm * cnt
		while last + mini <= x:
			if x - last in dic:
				ans += dic[x - last]
			last += cnt
		if x == 0:
			ans += 1
		print(ans)
	else:
		ans = 0
		mm = (abs(x) - abs(mini)) // abs(cnt)
		if mm > 1:
			mm = abs(mm) - 2
			last = mm * cnt
		while last + maxi >= x:
			if x - last in dic:
				ans += dic[x - last]
			last += cnt
		if x == 0:
			ans += 1
		print(ans)


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
t = read_int()
for i in range(t):
	(n, x) = read_int_line()
	s = read_line()
	p0 = [0] * n
	p1 = [0] * n
	if s[0] == '1':
		p1[0] = 1
	else:
		p0[0] = 1
	for i in range(1, n):
		if s[i] == '1':
			p1[i] = p1[i - 1] + 1
			p0[i] = p0[i - 1]
		else:
			p1[i] = p1[i - 1]
			p0[i] = p0[i - 1] + 1
	a = [0] * n
	for i in range(n):
		a[i] = p0[i] - p1[i]
	if a[-1] == 0:
		ans = 0
		if x == 0:
			ans += 1
		for i in range(n):
			if a[i] == x:
				ans += 1
		if ans > 0:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		if x == 0:
			ans += 1
		b = [(x - a[i]) / a[n - 1] for i in range(n)]
		for i in b:
			if i == int(i) and i >= 0:
				ans += 1
		print(ans)


T = int(input())
for i in range(T):
	line = str(input()).split(' ')
	len_string = int(line[0])
	desired_balance = int(line[1])
	string = str(input())
	string_balance = []
	balance = 0
	for el in string:
		if el == '0':
			balance += 1
			string_balance.append(balance)
		else:
			balance -= 1
			string_balance.append(balance)
	periodic_addition = string_balance[-1]
	numof_prefixes = 0
	if desired_balance == 0:
		numof_prefixes += 1
	if periodic_addition == 0 and desired_balance in string_balance:
		print(-1, end='\n')
		continue
	elif periodic_addition == 0:
		numof_prefixes += string_balance.count(desired_balance)
		print(numof_prefixes)
		continue
	for bal in string_balance:
		if (desired_balance - bal) % periodic_addition == 0 and (periodic_addition < 0 and bal >= desired_balance or (periodic_addition > 0 and bal <= desired_balance)):
			numof_prefixes += 1
	print(numof_prefixes, end='\n')


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	(n, x) = read_int_line()
	s = read_line()
	l = [0 for i in range(n)]
	if s[0] == '0':
		l[0] = 1
	else:
		l[0] = -1
	cnt = 0
	for i in range(1, n):
		if s[i] == '1':
			l[i] = l[i - 1] - 1
		else:
			l[i] = l[i - 1] + 1
	f = False
	for i in range(n):
		if x - l[i] == 0 and l[n - 1] == 0:
			f = True
	if not f and l[n - 1] != 0:
		for j in range(n):
			if (x - l[j]) % l[n - 1] == 0:
				if (x - l[j]) // l[n - 1] * n + j + 1 >= 0:
					cnt += 1
		print(cnt)
	elif not f and l[n - 1] == 0:
		print(0)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	s = input()
	win = [0 for i in range(n)]
	diff = s.count('0') - s.count('1')
	val = 0
	ct = 1 if x == 0 else 0
	for c in range(n):
		if s[c] == '0':
			val += 1
		else:
			val -= 1
		win[c] = x - val
	for c in range(n):
		if win[c] == 0 and diff == 0:
			ct = -1
			break
		elif diff != 0 and win[c] % diff == 0 and (win[c] // diff >= 0):
			ct += 1
	print(ct)


for t in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	s = input()
	l = []
	zero = 0
	one = 0
	for i in s:
		if i == '1':
			one += 1
		else:
			zero += 1
		l.append(zero - one)
	add = l[-1]
	if add == 0:
		if x in l:
			print(-1)
		else:
			print(1 if x == 0 else 0)
	else:
		res = 0
		for i in l:
			if (x - i) % add == 0 and (x - i) // add >= 0:
				res += 1
		if x == 0:
			res += 1
		print(res)


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	s = list(map(int, input()))
	kek = dict()
	cnt = 0
	for elem in s:
		if elem == 1:
			cnt -= 1
		else:
			cnt += 1
		if cnt in kek:
			kek[cnt] += 1
		else:
			kek[cnt] = 1
	ans = 0
	if x == 0:
		ans = 1
	if cnt == 0:
		for elem in kek:
			if elem == x or x == 0:
				ans = -1
				break
	if ans == -1:
		ans = -1
	elif cnt != 0:
		for elem in kek:
			if (x - elem) % cnt == 0 and (x - elem) // cnt >= 0:
				ans += kek[elem]
	print(ans)


t = int(input())
for tt in range(t):
	(n, x) = map(int, input().split())
	s = input()
	cnt = [0 for i in range(n + 1)]
	for i in range(1, n + 1):
		cnt[i] = cnt[i - 1]
		if s[i - 1] == '0':
			cnt[i] += 1
		else:
			cnt[i] -= 1
	ans = 0
	if x == 0:
		ans = 1
	for i in range(1, n + 1):
		if cnt[n] != 0 and (x - cnt[i]) % cnt[n] == 0 and ((x - cnt[i]) // cnt[n] >= 0):
			ans += 1
		elif x == cnt[i]:
			ans = -1
			break
	print(ans)


t = int(input())
for q in range(t):
	(l, x) = map(int, input().split())
	s = input()
	pref = [0 for i in range(l)]
	for k in range(l):
		if s[k] == '0':
			pref[k] = 1 + pref[k - 1]
		else:
			pref[k] = pref[k - 1] - 1
	isEx = False
	answ = 0
	if pref[l - 1] == 0 and x in pref:
		answ = -1
	else:
		if x == 0:
			answ = 1
		for i in range(l):
			if x - pref[i] == 0:
				answ += 1
			elif pref[l - 1] != 0:
				if (x - pref[i]) % pref[l - 1] == 0 and (x - pref[i]) / pref[l - 1] > 0:
					answ += 1
	print(answ)


def solve(string, target):
	balances = []
	balance = 0
	for digit in string:
		balance += 1 if digit == '0' else -1
		balances.append(balance)
	count = 1 if target == 0 else 0
	for balance in balances:
		if balances[-1] == 0:
			if balance == target:
				return -1
		elif target % balances[-1] == balance % balances[-1]:
			if (target - balance) // balances[-1] >= 0:
				count += 1
	return count
for T in range(int(input())):
	(n, x) = map(int, input().split())
	print(solve(input(), x))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	l = len(s)
	c0 = s.count('0')
	c1 = s.count('1')
	df = c0 - c1
	cnt = 0
	num = [0]
	for i in range(l - 1):
		if s[i] == '0':
			cnt += 1
		else:
			cnt -= 1
		num.append(cnt)
	ans = 0
	if df:
		for nm in num:
			if (x - nm) % df == 0:
				if (x - nm) // df >= 0:
					ans += 1
		print(ans)
	else:
		inf = False
		for nm in num:
			if x == nm:
				print(-1)
				inf = True
				break
		if not inf:
			print(0)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = list(map(int, list(input())))
	c01 = 0
	for j in range(n):
		if s[j] == 0:
			c01 = c01 + 1
		else:
			c01 = c01 - 1
	res = 0
	k = 0
	flag = 0
	for j in range(n):
		if c01 == 0:
			if k == x:
				flag = 1
				print(-1)
				break
		elif c01 > 0:
			if x >= k and (x - k) % c01 == 0:
				res = res + 1
		elif k >= x and (k - x) % c01 == 0:
			res = res + 1
		if s[j] == 0:
			k = k + 1
		else:
			k = k - 1
	if flag == 0:
		print(res)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	mas = []
	mas.append(0)
	if s[0] == '0':
		mas.append(1)
	else:
		mas.append(-1)
	for i in range(1, n):
		if s[i] == '0':
			mas.append(mas[i] + 1)
		else:
			mas.append(mas[i] - 1)
	scnt = mas[-1]
	otv = 0
	endl = False
	fpref = False
	lpref = False
	for sas in range(len(mas)):
		i = mas[sas]
		prev = x - i
		if prev == 0 and scnt == 0:
			endl = True
			break
		if prev != 0 and scnt == 0:
			continue
		if prev % scnt == 0 and prev // scnt >= 0:
			if sas == 0:
				fpref = True
			if sas == len(mas) - 1:
				lpref = True
			otv += 1
	if lpref and fpref:
		otv -= 1
	if endl:
		print(-1)
		continue
	print(otv)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	tab = [0]
	(a, b) = (0, 0)
	for i in range(n):
		if s[i] == '0':
			a += 1
		else:
			b += 1
		tab.append(a - b)
	diff = a - b
	count = 0
	if diff != 0:
		if x == 0:
			count += 1
		for i in range(1, n + 1):
			if tab[i] < x and diff > 0:
				if tab[i] % diff == x % diff:
					count += 1
			elif tab[i] > x and diff < 0:
				if tab[i] % diff == x % diff:
					count += 1
			elif tab[i] == x:
				count += 1
	else:
		for i in range(n + 1):
			if tab[i] == x:
				count = -1
	print(count)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	string = input()
	arr = []
	c = 0
	for ch in string:
		c = c + 1 if ch == '0' else c - 1
		arr.append(c)
	freq = dict(Counter(arr))
	if not c:
		if x in freq:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		for item in freq:
			if item < x and c < 0:
				continue
			if item > x and c > 0:
				continue
			if (x - item) % c == 0:
				ans += freq[item]
		if not x:
			ans += 1
		print(ans)


import math
sign = lambda x: math.copysign(1, x)
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	sums = {}
	pref_sum = 0
	for sym in map(int, input()):
		if sym == 0:
			pref_sum += 1
		else:
			pref_sum -= 1
		sums[pref_sum] = sums.get(pref_sum, 0) + 1
	ans = 1 if x == 0 else 0
	if pref_sum == 0:
		ans = -1 if x in sums else 0
	else:
		for (pref, cnt) in sums.items():
			if (x - pref) % pref_sum == 0:
				if (x - pref) // pref_sum >= 0:
					ans += cnt
	print(ans)


import sys
input = sys.stdin.readline

def calc(s):
	return s.count('0') - s.count('1')
for nt in range(int(input())):
	(n, k) = map(int, input().split())
	s = input()
	b = calc(s)
	x = calc(s[0])
	p = [x]
	for i in range(1, n):
		x += calc(s[i])
		p.append(x)
	if b == 0 and k in p:
		print(-1)
		continue
	if b == 0 and k not in p:
		print(0)
		continue
	ans = 1 if k == 0 else 0
	for i in p:
		if (k - i) * b >= 0 and (k - i) % b == 0:
			ans += 1
	print(ans)


from itertools import accumulate
from collections import defaultdict
N = int(input())
for _ in range(N):
	x = int(input().split()[1])
	s = input()
	s = list(map(lambda c: -int(c) * 2 + 1, s))
	psum = list(accumulate(s))
	step = psum[-1]
	counts = defaultdict(int)
	for p in psum:
		counts[p] += 1
	if x == 0:
		res = 1
	else:
		res = 0
	if step == 0:
		if x in psum:
			print(-1)
		else:
			print(0)
	else:
		for (k, v) in counts.items():
			if step > 0 and k > x or (step < 0 and k < x):
				continue
			if (x - k) % step == 0:
				res += v
		print(res)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	string = input()
	num = [0]
	for i in string:
		if i == '1':
			num.append(num[-1] - 1)
		else:
			num.append(num[-1] + 1)
	ans = 0
	isInfi = False
	for i in num[:-1]:
		if num[n] == 0:
			if i == x:
				isInfi = True
		elif abs(x - i) % abs(num[n]) == 0:
			if (x - i) / num[n] >= 0:
				ans += 1
	if isInfi:
		print(-1)
	else:
		print(ans)


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	(n, x) = [int(x) for x in input().strip().split()]
	s = input().strip()
	a = [0]
	c = 0
	for si in s:
		if si == '0':
			c += 1
		else:
			c -= 1
		a.append(c)
	slen = len(s)
	cyc = a[slen] - a[0]
	ans = 0
	for i in range(1, slen + 1):
		if not cyc and x == a[i]:
			ans += 1
		if cyc and (x - a[i]) % cyc == 0 and ((x - a[i]) // cyc >= 0):
			ans += 1
	if ans > 0 and (not cyc):
		print('-1')
	else:
		if a[0] == x:
			ans += 1
		print(ans)


T = int(input())
for cs in range(T):
	(n, x) = map(int, input().split())
	s = input()
	p = [0]
	for i in range(n):
		p.append(p[i] + (1 if s[i] == '0' else -1))
	if p[n] == 0:
		cnt = 0
		for i in range(n):
			if p[i] == x:
				cnt = -1
				break
		print(cnt)
	else:
		cnt = 0
		for i in range(n):
			if (x - p[i]) % p[n] == 0 and (x - p[i]) / p[n] >= 0:
				cnt += 1
		print(cnt)


from math import *
zzz = int(input())
for zz in range(zzz):
	(n, x) = map(int, input().split())
	s = [int(i) for i in input()]
	a = []
	bal = 0
	for i in range(n):
		if s[i] > 0:
			bal -= 1
		else:
			bal += 1
		a.append(bal)
	if x > 0 and a[-1] < 0 and (max(a) < x):
		print(0)
	elif x < 0 and a[-1] > 0 and (min(a) > x):
		print(0)
	elif a[-1] != 0:
		ans = 0
		for i in range(n):
			if (x - a[i]) % a[-1] == 0 and (x - a[i]) // a[-1] >= 0:
				ans += 1
		if x == 0:
			ans += 1
		print(ans)
	elif x in a:
		print(-1)
	else:
		print(0)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	ka = s.count('0') - s.count('1')
	pref = [0]
	for i in s:
		pref.append(pref[-1] + int(i))
	ans = 0
	flag = 0
	for i in range(1, len(pref)):
		z = x - (i - 2 * pref[i])
		if ka == 0:
			if z == 0:
				flag = 1
				break
		elif z // ka == z / ka and z // ka >= 0:
			ans += 1
	if flag:
		print(-1)
		continue
	if x == 0:
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = [int(z) for z in input().split(' ')]
	s = input()
	c = 0
	m = -10 ** 10
	n = 10 ** 10
	q = []
	M = b % a
	ans = 0
	for j in range(a):
		if s[j] == '0':
			c += 1
		else:
			c -= 1
		m = max(m, c)
		n = min(n, c)
		q.append(c)
	Q = [0] * (2 * len(q) + 1)
	for j in range(a):
		Q[q[j] + a] += 1
	if c == 0 and b <= m and (b >= n):
		print(-1)
	elif c == 0:
		print(0)
	else:
		Z = 0
		for j in Q:
			if (b - (Z - a)) % c == 0 and (b - Z + a) * c >= 0:
				ans += j
			Z += 1
		if b == 0:
			print(ans + 1)
		else:
			print(ans)


def solve(n, x, s):
	p = []
	(z_count, o_count) = (s.count('0'), s.count('1'))
	b = 0
	for c in s:
		if c == '0':
			b += 1
		else:
			b -= 1
		p.append(b)
	res = 0
	if z_count == o_count:
		if x in p:
			res = -1
	else:
		if x == 0:
			res += 1
		diff = p[-1]
		for x0 in p:
			if diff > 0:
				if x0 <= x:
					tmp = x - x0
					if tmp % diff == 0:
						res += 1
			if diff < 0:
				if x0 >= x:
					tmp = x - x0
					if tmp % diff == 0:
						res += 1
	print(res)
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	solve(n, x, s)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split(' '))
	s = input()
	if s[0] == '0':
		p = [1]
		z = 1
		o = 0
	else:
		p = [-1]
		o = 1
		z = 0
	for i in range(1, len(s)):
		if s[i] == '0':
			z += 1
			p.append(p[i - 1] + 1)
		else:
			o += 1
			p.append(p[i - 1] - 1)
	f = z - o
	ans = 0
	if f == 0:
		if x in p:
			print(-1)
		else:
			print(0)
		continue
	for i in p:
		if (x - i) % f == 0:
			if (x - i) // f >= 0:
				ans += 1
	if x == 0:
		ans += 1
	print(ans)


import collections
for i in range(int(input())):
	(n, x) = map(int, input().split())
	sum = 0
	cnt = 0
	s = input()
	a = collections.defaultdict(lambda : 0)
	for j in s:
		if j == '0':
			sum = sum + 1
		else:
			sum = sum - 1
		a[sum] = a[sum] + 1
	if x == 0:
		cnt = 1
	if sum > 0:
		for i in a:
			if (x - i) % sum == 0 and x - i >= 0:
				cnt = cnt + a[i]
	elif sum == 0:
		for i in a:
			if i == x:
				cnt = -1
	elif sum < 0:
		for i in a:
			if (i - x) % (sum * -1) == 0 and i - x >= 0:
				cnt = cnt + a[i]
	print(cnt)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	arr = []
	bal = 0
	for a in s:
		if a == '0':
			bal += 1
		else:
			bal -= 1
		arr += [bal]
	count = 0
	bal2 = arr[-1]
	arr2 = []
	for a in s:
		if a == '0':
			bal += 1
		else:
			bal -= 1
		arr2 += [bal]
	if arr[0] == arr2[0]:
		if x in arr:
			print(-1)
		else:
			print(0)
		continue
	elif arr[0] < arr2[0]:
		diff = arr2[0] - arr[0]
		for a in arr:
			if a <= x and (a - x) % diff == 0:
				count += 1
	else:
		diff = arr[0] - arr2[0]
		for a in arr:
			if x <= a and (x - a) % diff == 0:
				count += 1
	if x == 0:
		count += 1
	print(count)


t = int(input())
for i in range(t):
	ls = input().split()
	n = int(ls[0])
	x = int(ls[1])
	s = input()
	if s[0] == '0':
		bal = [1]
	else:
		bal = [-1]
	for j in range(1, n):
		if s[j] == '0':
			bal.append(bal[j - 1] + 1)
		else:
			bal.append(bal[j - 1] - 1)
	cnt = 0
	e = False
	if x == 0:
		cnt += 1
	for j in bal:
		if x == j:
			if bal[n - 1] == 0:
				cnt = -1
				break
			else:
				cnt += 1
		if bal[n - 1] > 0:
			if x > j and (x - j) % bal[n - 1] == 0:
				cnt += 1
		elif bal[n - 1] < 0:
			if x < j and (j - x) % bal[n - 1] == 0:
				cnt += 1
	print(cnt)


import math
tt = int(input())
for i in range(tt):
	(n, x) = map(int, input().split())
	s = input()
	a = 1
	b = {}

	def bind(x):
		return -(2 * x - 1)
	if x < 0:
		a = -1
		x = -x
	sbal = 0
	for i in s:
		sbal += bind(int(i)) * a
		b[sbal] = b.get(sbal, 0) + 1
	ans = 0
	if sbal == 0:
		if b.get(x, 0) != 0:
			print(-1)
		else:
			print(0)
		continue
	elif sbal > 0:
		add = x - max(b)
		if add > 0:
			x -= math.ceil(add / sbal) * sbal
		for i in range(x, min(b) - sbal, -sbal):
			ans += b.get(i, 0)
	else:
		dec = min(b) - x
		if dec > 0:
			x += math.ceil(dec / sbal) * sbal
		for i in range(x, max(b) - sbal, -sbal):
			ans += b.get(i, 0)
	if x == 0:
		ans += 1
	print(ans)


t = input()
t = int(t)
res = []
n = []
x = []
s = []
for i in range(t):
	(n1, x1) = input().split()
	s1 = str(input())
	(n1, x1) = (int(n1), int(x1))
	n.append(n1)
	x.append(x1)
	s.append(s1)
for i in range(t):
	b = []
	b.append(1 - 2 * int(s[i][0]))
	for j in range(1, n[i]):
		b.append(b[j - 1] + 1 - 2 * int(s[i][j]))
	inc = int(b[-1])
	if inc == 0:
		if b.count(x[i]):
			res.append(-1)
		else:
			res.append(0)
		continue
	if inc > 0:
		cnt = 0
		for j in range(n[i]):
			if (x[i] - b[j]) % inc == 0 and x[i] - b[j] >= 0:
				cnt += 1
		res.append(cnt)
		continue
	if inc < 0:
		cnt = 0
		for j in range(n[i]):
			if (x[i] - b[j]) % inc == 0 and x[i] - b[j] <= 0:
				cnt += 1
		res.append(cnt)
		continue
for i in range(t):
	if res[i] != -1:
		res[i] += int(1 - bool(x[i]))
for i in range(t):
	print(res[i])


def solve(dp, n, x):
	if dp[n] == 0:
		for i in range(n):
			if dp[i] == x:
				return -1
		return 0
	else:
		cnt = 0
		for i in range(n):
			if (x - dp[i]) * dp[n] >= 0 and (x - dp[i]) % dp[n] == 0:
				cnt += 1
		return cnt
for t in range(int(input())):
	(n, x) = map(int, input().split(' '))
	s = input()
	dp = list((0 for x in range(n + 1)))
	count = 0
	for i in range(n):
		if s[i] == '0':
			count += 1
		else:
			count -= 1
		dp[i + 1] = count
	ans = solve(dp, n, x)
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	(a, b) = (0, 0)
	count = 0
	z = []
	for i in range(n):
		if s[i] == '0':
			a += 1
		else:
			b += 1
		z.append(a - b)
	if x == 0:
		count += 1
		count += z.count(0)
		if z[-1] == 0:
			count = -1
		else:
			for i in range(len(z)):
				if (x - z[i]) % z[-1] == 0 and z[-1] * (x - z[i]) > 0:
					count += 1
	elif z[-1] == 0:
		for i in range(len(z)):
			if x == z[i]:
				count += 1
		if count > 0:
			count = -1
	else:
		for i in range(len(z)):
			if x == z[i]:
				count += 1
		for i in range(len(z)):
			if (x - z[i]) % z[-1] == 0 and z[-1] * (x - z[i]) > 0:
				count += 1
	print(count)


def solve():
	(n, x) = map(int, input().split())
	s = input()
	cnt = [0 for i in range(n)]
	prev = 0
	for i in range(n):
		if s[i] == '0':
			cnt[i] = prev + 1
			prev = cnt[i]
		else:
			cnt[i] = prev - 1
			prev = cnt[i]
	ans = 0
	increase = cnt[-1]
	for i in range(n):
		if increase != 0 and (x - cnt[i]) % increase == 0:
			if cnt[i] < x and increase <= 0:
				continue
			elif cnt[i] > x and increase >= 0:
				continue
			else:
				ans += 1
	if cnt[-1] == 0:
		if x in cnt:
			print(-1)
		elif x != 0:
			print(0)
		else:
			print(1)
	elif ans == 0 and x == 0:
		print(1)
	elif x == 0:
		print(ans + 1)
	else:
		print(ans)
for i in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	b = [0] * n
	if s[0] == '1':
		b[0] = -1
	else:
		b[0] = 1
	for i in range(1, n):
		if s[i] == '1':
			b[i] = b[i - 1] - 1
		else:
			b[i] = b[i - 1] + 1
	if b[n - 1] == 0:
		if x in b:
			print(-1)
		else:
			print(0)
	else:
		count = 0
		if x == 0:
			count += 1
		for i in range(n):
			d = x - b[i]
			if d * b[n - 1] >= 0 and d % b[n - 1] == 0:
				count += 1
		print(count)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	a = [0]
	for c in s:
		if c == '0':
			a.append(a[-1] + 1)
		else:
			a.append(a[-1] - 1)
	(*a, m) = a
	mi = min(a) if a else 0
	ma = max(a) if a else 0
	if m == 0:
		print(-1 if mi <= x <= ma else 0)
		continue
	total = 0
	for v in a:
		if v % m == x % m:
			if x <= v and m < 0 or (x >= v and m > 0):
				total += 1
	print(total)


import sys
import io
from collections import defaultdict, Counter
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(N, x) = [int(i) for i in input().split()]
		l = [int(i) for i in input().strip()]
		pref = [0 for i in range(N + 1)]
		for i in range(1, N + 1):
			pref[i] = pref[i - 1] + (-1 if l[i - 1] == 1 else 1)
		if pref[N] == 0 and x in pref:
			print(-1)
		elif pref[N] == 0:
			print(0)
		else:
			lst = pref[N]
			ans = 0
			for i in range(N):
				curr = x - pref[i]
				if curr * lst >= 0 and curr % lst == 0:
					ans += 1
			print(ans)
main()


from sys import stdin

def compute(s, target):
	A = [None] * len(s)
	A[0] = 0
	for i in range(1, len(s)):
		if s[i - 1] == '0':
			A[i] = A[i - 1] + 1
		else:
			A[i] = A[i - 1] - 1
	if s[-1] == '0':
		b = A[-1] + 1
	else:
		b = A[-1] - 1
	if b == 0:
		if target in A:
			print(-1)
		else:
			print(0)
	else:
		if b < 0:
			bp = -b
			count = sum((1 for v in A if v % bp == target % bp and v >= target))
		else:
			count = sum((1 for v in A if v % b == target % b and v <= target))
		print(count)
t = int(stdin.readline())
for i in range(t):
	(n, target) = (int(v) for v in stdin.readline().split())
	s = stdin.readline().strip()
	compute(s, target)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = list(map(int, sys.stdin.readline().split()))
	re = 0
	if m == 0:
		re += 1
	s = sys.stdin.readline().split()[0]
	n_sum = []
	for (i, c) in enumerate(s):
		if i == 0:
			n_sum.append(1 if c == '0' else -1)
		else:
			n_sum.append(n_sum[i - 1] + (1 if c == '0' else -1))
	cycle = n_sum[-1:][0]
	if cycle == 0:
		flag = False
		for i in n_sum:
			if i == m:
				flag = True
				break
		if flag:
			print(-1)
		else:
			print(0)
		continue
	for i in n_sum:
		if (m - i) % cycle == 0 and int((m - i) / cycle) >= 0:
			re += 1
	print(re)


def sign(x):
	if x == 0:
		return 0
	else:
		return x // abs(x)
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	dic = []
	cnt = 0
	for j in s:
		if j == '0':
			cnt += 1
		else:
			cnt -= 1
		dic.append(cnt)
	ans = 0
	(cnttmp, ava) = (0, False)
	if x == 0:
		ans += 1
	if cnt == 0:
		if x in dic:
			ans = -1
		else:
			ans = 0
	else:
		for j in dic:
			if (x - j) % cnt == 0 and sign(x - j) * sign(cnt) >= 0:
				ans += 1
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

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

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

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 zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, x) = sep()
	a = list(inp())
	for i in range(n):
		a[i] = int(a[i])
	a = a
	pre = [0] * len(a)
	cnt1 = 0
	cnt0 = 0
	for i in range(len(a)):
		if a[i] == 1:
			cnt1 += 1
		else:
			cnt0 += 1
		pre[i] = cnt0 - cnt1
	if pre[n - 1] == 0:
		if pre.count(x) > 0:
			print(-1)
		elif x == 0:
			print(1)
		else:
			print(0)
	else:
		curr = abs(pre[n - 1])
		cnt = 0
		if pre[n - 1] < 0:
			for i in range(n):
				if pre[i] >= x and (pre[i] - x) % curr == 0:
					cnt += 1
		else:
			for i in range(n):
				if pre[i] <= x and (x - pre[i]) % curr == 0:
					cnt += 1
		if x == 0:
			print(cnt + 1)
		else:
			print(cnt)
testcase(int(inp()))


t = int(input())
for T in range(t):
	(n, x) = [int(x) for x in input().split()]
	s = input()
	(c0, c1) = (0, 0)
	l = [0]
	for i in range(n):
		if s[i] == '0':
			c0 += 1
		else:
			c1 += 1
		l.append(c0 - c1)
	if l[-1] == 0:
		if x in l:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		val = l[-1]
		for i in range(n):
			if (x - l[i]) % val == 0 and (x - l[i]) // val >= 0:
				ans += 1
		print(ans)


for t in range(int(input())):
	(n, x) = map(int, input().split(' '))
	binary = input()
	balance = 0
	res = 0
	for c in binary:
		if c == '0':
			balance += 1
		else:
			balance -= 1
	currBal = 0
	for i in range(n):
		if balance == 0 and currBal == x:
			res = 1
			break
		if balance != 0 and (x - currBal) % balance == 0 and ((x - currBal) / balance >= 0):
			res += 1
		if binary[i] == '0':
			currBal += 1
		else:
			currBal -= 1
	if balance == 0 and res > 0:
		print(-1)
	else:
		print(res)


def str_balance(s):
	return s.count('0') - s.count('1')

def val(c):
	if c == '1':
		return -1
	return 1

def arr_balance(s):
	l = [0]
	for c in s:
		l.append(l[-1] + val(c))
	return l[1:]
INFINITE = -1

def calc_prefix_number(s, n, x):
	l = arr_balance(s)
	steps = l[-1]
	if steps == 0:
		if x in l:
			return INFINITE
		return 0
	cnt = 0
	if x == 0:
		cnt += 1
	for cell in l:
		if (x - cell) % steps == 0 and (x - cell) * steps >= 0:
			cnt += 1
	return cnt
testcases = int(input())
for _ in range(testcases):
	(n, x) = [int(p) for p in input().split()]
	s = input()
	print(calc_prefix_number(s, n, x))


n = int(input())
for i in range(n):
	[n, x] = [*map(int, input().split())]
	s = [int(i) for i in input()]
	diffs = [0] * (n + 1)
	acc = 0
	for j in range(n):
		acc = acc + 1 if s[j] == 0 else acc - 1
		diffs[j + 1] = acc
	b = diffs[-1]
	if b == 0:
		if x in diffs:
			print(-1)
		else:
			print(0)
		continue
	res = 0
	for v in range(n):
		if (x - diffs[v]) % b == 0 and (x - diffs[v]) // b >= 0:
			res += 1
	print(res)


for _ in range(int(input())):
	(x, y) = [int(x) for x in input().split()]
	s = input()
	(b, z, ans, flag) = (s.count('0') - s.count('1'), 0, 0, False)
	if y == 0:
		ans = 1
	for elem in s:
		z += (elem == '0') - (elem == '1')
		if b == 0 and z == y:
			flag = True
			print(-1)
			break
		if z == y or ((y - z) * b > 0 and abs(y - z) % abs(b) == 0):
			ans += 1
	if not flag:
		print(ans)


def solve():
	(n, x) = map(int, input().split())
	s = input()
	if s.count('0') == s.count('1'):
		cnt = 0
		if x == 0:
			print(-1)
			return
		for i in range(n):
			if s[i] == '0':
				cnt += 1
			else:
				cnt -= 1
			if cnt == x:
				print('-1')
				return
		print(0)
		return
	else:
		d = s.count('0') - s.count('1')
		cnt = 0
		ans = 0
		for i in range(n):
			if s[i] == '0':
				cnt += 1
			else:
				cnt -= 1
			if (x - cnt) * d > 0:
				if abs(cnt - x) % d == 0:
					ans += 1
			if x - cnt == 0:
				ans += 1
		if x == 0:
			ans += 1
		print(ans)
		return
test = int(input())
for _ in range(test):
	solve()


import sys
from collections import Counter
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def countPrefix(s, x):
	if x < 0:
		s = s.replace('0', '#').replace('1', '0').replace('#', '1')
		x = -x
	bal = 0
	ctr = Counter()
	maxBal = minBal = 0
	for c in s:
		if c == '0':
			bal += 1
		else:
			bal -= 1
		ctr[bal] += 1
		maxBal = max(maxBal, bal)
		minBal = min(minBal, bal)
	if bal == 0:
		if x <= maxBal:
			return -1
		else:
			return 0
	elif bal < 0:
		ans = 0
		if maxBal >= x:
			k = 0
			while maxBal + k * bal >= x:
				ans += ctr[x - k * bal]
				k += 1
	else:
		if maxBal >= x:
			k = 0
		else:
			k = (x - maxBal) // bal
		ans = 0
		while minBal + k * bal <= x:
			ans += ctr[x - k * bal]
			k += 1
	if x == 0:
		ans += 1
	return ans
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	print(countPrefix(s, x))


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		s = input().rstrip()
		(o, z, f) = (0, 0, 0)
		for i in range(n):
			if s[i] == '0':
				z += 1
			else:
				o += 1
			if z - o == x:
				f = 1
		if z - o == 0 and f:
			print(-1)
		elif z - o == 0 and (not f):
			print(0)
		else:
			(ans, oo, zz) = (0, 0, 0)
			for i in range(n):
				if s[i] == '0':
					zz += 1
				else:
					oo += 1
				if (x - (zz - oo)) % (z - o) == 0 and (x - (zz - oo)) * (z - o) >= 0:
					ans += 1
			print(ans + (x == 0))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
debugging = False

def dprint(*args):
	if debugging:
		print(*args)
	else:
		pass
shift = 100001
t = intput()
for _ in range(t):
	(n, x) = intsput()
	s = input()
	balances = [0] * 200002
	b = 0
	for i in range(n):
		if s[i] == '1':
			b -= 1
		else:
			b += 1
		balances[b + shift] += 1
	finalb = b
	if finalb == 0 and 0 <= x + shift < len(balances) and balances[x + shift]:
		print(-1)
		continue
	elif finalb == 0:
		print(0)
		continue
	k = x
	ans = 0
	if x == 0:
		ans += 1
	if len(balances) > k + shift >= 0:
		while len(balances) > k + shift >= 0:
			ans += balances[k + shift]
			k -= finalb
		print(ans)
	elif k + shift >= len(balances) and finalb > 0:
		k -= (k + shift - len(balances) + 1) // finalb * finalb
		while k + shift >= len(balances):
			k -= finalb
		while len(balances) > k + shift >= 0:
			ans += balances[k + shift]
			k -= finalb
		print(ans)
	elif k + shift < 0 and finalb < 0:
		k += (0 - (k + shift)) // -finalb * -finalb
		while k + shift < 0:
			k += -finalb
		while len(balances) > k + shift >= 0:
			ans += balances[k + shift]
			k -= finalb
		print(ans)
	else:
		print(0)


import math, collections, sys
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	val = []
	for i in s:
		if not val:
			if i == '1':
				val.append(-1)
			else:
				val.append(1)
		elif i == '1':
			val.append(val[-1] - 1)
		else:
			val.append(val[-1] + 1)
	inc = val[-1]
	if inc == 0:
		if x in val:
			print(-1)
		elif x == 0:
			print(1)
		else:
			print(0)
	else:
		count = 0
		for i in val:
			if (x - i) / inc == int((x - i) // inc) and (x - i) / inc >= 0:
				count += 1
		if x == 0:
			count += 1
		print(count)


t = int(input())
for i in range(t):
	nx = list(map(int, input().split()))
	n = nx[0]
	x = nx[1]
	s = input()
	ls = {}
	d = 0
	for ch in s:
		if ch == '0':
			d += 1
		else:
			d -= 1
		if d in ls.keys():
			ls[d] = ls[d] + 1
		else:
			ls[d] = 1
	if d == 0:
		if x in ls.keys():
			print(-1)
		elif x == 0:
			print(1)
		else:
			print(0)
	else:
		sum = 0
		for key in ls.keys():
			if x - key == 0 or ((x - key) * d > 0 and abs(x - key) % abs(d) == 0):
				sum += ls[key]
		if x == 0:
			print(sum + 1)
		else:
			print(sum)


T = int(input().strip())
for _ in range(T):
	(n, x) = map(int, input().split())
	s = input().strip()
	cnt = {}
	bal = 0
	(lo, hi) = (None, None)
	for c in s:
		if c == '0':
			bal += 1
		else:
			bal -= 1
		cnt[bal] = cnt.get(bal, 0) + 1
		lo = min(lo, bal) if lo else bal
		hi = max(hi, bal) if hi else bal
	if bal == 0:
		if x >= lo and x <= hi:
			print('-1')
		else:
			print('0')
	else:
		total = 0
		if x == 0:
			total += 1
		if bal < 0 and x < lo:
			x += bal * ((lo - x) // bal)
		elif bal > 0 and x > hi:
			x += bal * ((hi - x) // bal)
		while x in cnt:
			total += cnt[x]
			x -= bal
		print(total)


from collections import Counter
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	cnt = Counter()
	bal = 0
	for c in input():
		cnt[bal] += 1
		bal += (c == '0') - (c == '1')
	if bal == 0:
		if cnt[x]:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		for k in list(cnt.keys()):
			xmk = x - k
			if not xmk % bal and xmk * bal >= 0:
				ans += cnt[k]
		print(ans)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	r = [0]
	for i in range(n):
		if int(s[i]) == 0:
			r.append(1 + int(r[i]))
		else:
			r.append(int(r[i]) - 1)
	total = r[-1]
	add = 0
	if total == 0:
		for i in range(1, n + 1):
			if r[i] == x:
				add += 1
		if add > 0:
			print(-1)
			continue
		else:
			print(0)
			continue
	for i in range(1, n + 1):
		if (x - r[i]) * total >= 0:
			if (x - r[i]) % total == 0:
				add += 1
	if x == 0:
		print(add + 1)
	else:
		print(add)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

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

def S():
	return input()

def MS():
	return map(str, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def input():
	return sys.stdin.readline().rstrip()

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False

def main():
	T = I()
	n = [0] * T
	x = [0] * T
	s = [''] * T
	for i in range(T):
		(n[i], x[i]) = MI()
		s[i] = S()
	for t in range(T):
		Q = s[t]
		X = x[t]
		one = 0
		zero = 0
		ans = 0
		a = [0] * (len(Q) + 1)
		for i in range(len(Q)):
			if Q[i] == '1':
				one += 1
			else:
				zero += 1
			a[i + 1] += zero - one
		for i in range(len(a)):
			if a[i] == X:
				ans += 1
		end = a[-1]
		if end == 0 and ans != 0:
			print(-1)
			continue
		if end == 0 and ans == 0:
			print(0)
			continue
		for i in range(1, len(a)):
			if end > 0 and a[i] < X and ((X - a[i]) % end == 0):
				ans += 1
			elif end < 0 and a[i] > X and ((a[i] - X) % abs(end) == 0):
				ans += 1
		print(ans)
main()


sd = []
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	bal = []
	b = 0
	for c in s:
		if c == '0':
			b += 1
		else:
			b -= 1
		bal.append(b)
	ans = 0
	for d in bal:
		if x == d and b == 0:
			ans = -1
			break
		elif b != 0:
			if (x - d) % b == 0 and (x - d) // b >= 0:
				ans += 1
	if x == 0 and ans != -1:
		ans += 1
	sd.append(str(ans))
print('\n'.join(sd))


for t in range(int(input())):
	ans = 0
	(n, x) = [int(j) for j in input().split()]
	s = input()
	l = [0] * n
	last = 0
	for i in range(n):
		if s[i] == '0':
			l[i] = last + 1
			last += 1
		else:
			l[i] = last - 1
			last -= 1
	for i in range(n):
		if l[n - 1] != 0:
			if (x - l[i]) % l[n - 1] == 0 and (x - l[i]) * l[n - 1] >= 0:
				ans += 1
		elif x - l[i] == 0:
			ans = -1
			break
	if x == 0 and ans != -1:
		ans += 1
	print(ans)


def solve():
	t = int(input())
	while t > 0:
		(n, x) = map(int, input().split())
		s = input()
		ans = 0
		inf = 0
		p = 0
		if x == 0:
			ans += 1
		index = 0
		cnt_0 = 0
		cnt_1 = 0
		for i in range(n):
			if s[i] == '0':
				cnt_0 += 1
			else:
				cnt_1 += 1
		ini_diff = cnt_0 - cnt_1
		while index < n:
			if s[index] == '0':
				p += 1
			else:
				p -= 1
			if ini_diff == 0:
				if p == x:
					inf = 1
					break
			elif (x - p) % ini_diff == 0:
				m = (x - p) / ini_diff + 1
				if m > 0:
					ans += 1
			index += 1
		if inf:
			print(-1)
		else:
			print(ans)
		t -= 1
solve()


from itertools import accumulate
from collections import defaultdict
T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	s = [1 if c == '0' else -1 for c in input()]
	accum = list(accumulate(s))
	count = defaultdict(int)
	for i in accum:
		count[i] += 1
	last = accum[-1]
	ans = 0
	if x == 0:
		ans = 1
	if last == 0:
		if count[x] > 0:
			ans = -1
	else:
		(ma, mi) = (max(accum), min(accum))
		if last > 0:
			x -= max(0, (x - ma + last - 1) // last * last)
		else:
			x += max(0, (mi - x + last - 1) // last * last)
		while last > 0 and x >= mi or (last < 0 and x <= ma):
			ans += count[x]
			x -= last
	print(ans)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def countPrefix(s, x):
	n = len(s)
	s = int(s, 2)
	if x < 0:
		mask = (1 << n) - 1
		s = ~s & mask
		x = -x
	bal = 0
	res = [0] * (n << 1 | 1)
	for d in reversed(range(n)):
		mask = 1 << d
		if s & mask:
			bal -= 1
		else:
			bal += 1
		res[n + bal] += 1
	if bal == 0:
		if x <= n and res[n + x] > 0:
			return -1
		else:
			return 0
	else:
		ans = 0
		if bal < 0:
			bal = -bal
			xRes = x % bal
			for i in range(n << 1 | 1):
				if (i - n) % bal == xRes and i - n >= x:
					ans += res[i]
		else:
			xRes = x % bal
			for i in range(n << 1 | 1):
				if (i - n) % bal == xRes and i - n <= x:
					ans += res[i]
	if x == 0:
		ans += 1
	return ans
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	print(countPrefix(s, x))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	data = [0]
	for y in s:
		if y == '1':
			data.append(data[-1] - 1)
		else:
			data.append(data[-1] + 1)
	ans = 0
	if x == 0:
		ans += 1
	if data[-1] != 0:
		for i in range(n):
			if (x - data[i + 1]) % data[-1] == 0 and (x - data[i + 1]) * data[-1] >= 0:
				ans += 1
	else:
		for i in range(n):
			if data[i + 1] == x:
				ans = -1
				break
	print(ans)


def do(n, x):
	s = input()
	sum = 0
	if x == 0:
		tj = {0: 1}
	else:
		tj = {}
	for i in range(n):
		if s[i] == '0':
			sum += 1
		else:
			sum -= 1
		if sum not in tj:
			tj[sum] = 1
		else:
			tj[sum] += 1
	ans = 0
	if sum == 0:
		if x in tj:
			print('-1')
			return
		else:
			print('0')
			return
	for k in tj:
		if x - k == 0:
			ans += tj[k]
		if (x - k) * sum > 0 and (x - k) % sum == 0:
			ans += tj[k]
	print(ans)
	return
N = int(input())
for _ in range(N):
	tem = input().split()
	(n, x) = (int(tem[0]), int(tem[1]))
	do(n, x)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	S = input()
	cnt0 = 0
	cnt1 = 0
	ans = 0
	if K == 0:
		ans += 1
	balance = 0
	for i in S:
		if i == '1':
			cnt1 += 1
		else:
			cnt0 += 1
		if cnt0 - cnt1 == K:
			ans += 1
	balance = cnt0 - cnt1
	if balance == 0:
		if ans != 0:
			print('-1')
		else:
			print('0')
	else:
		cnt1 = 0
		cnt0 = 0
		for i in S:
			bal = 0
			if i == '1':
				cnt1 += 1
			else:
				cnt0 += 1
			bal = balance + (cnt0 - cnt1)
			if (K - bal) % balance == 0:
				if (K - bal) // balance >= 0:
					ans += 1
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	data = [int(s[i]) for i in range(n)]
	for i in range(n):
		if data[i] == 0:
			data[i] = 1
		else:
			data[i] = -1
	for i in range(1, n):
		data[i] += data[i - 1]
	base = data[-1]
	if base < 0:
		base *= -1
		x *= -1
		for i in range(n):
			data[i] *= -1
	data.pop()
	data = [0] + data
	m = min(data)
	M = max(data)
	if base == 0:
		if M >= x >= m or x == 0:
			print(-1)
		else:
			print(0)
	else:
		res = 0
		for i in range(n):
			if (x - data[i]) % base == 0:
				tmp = (x - data[i]) // base
				if tmp >= 0:
					res += 1
		print(res)


import sys, array
t = int(input())
while t:
	(n, x) = map(int, sys.stdin.readline().split())
	s = sys.stdin.readline().replace('\n', '')
	a = array.array('i', range(n))
	cz = 0
	co = 0
	ans = 0
	for i in range(n):
		if s[i] == '0':
			cz += 1
			a[i] = cz - co
		else:
			co += 1
			a[i] = cz - co
	if x == 0:
		if a[n - 1] == 0:
			ans = -1
		elif a[n - 1] > 0:
			for each in a:
				if each == 0 or (each < 0 and abs(each) % a[n - 1] == 0):
					ans += 1
		elif a[n - 1] < 0:
			for each in a:
				if each == 0 or (each > 0 and abs(each) % abs(a[n - 1]) == 0):
					ans += 1
		if ans >= 0:
			ans += 1
	elif a[n - 1] == 0:
		if x in a:
			ans = -1
		else:
			ans = 0
	elif a[n - 1] > 0:
		for each in a:
			if each == x or (each < x and (x - each) % abs(a[n - 1]) == 0):
				ans += 1
	else:
		for each in a:
			if each == x or (each > x and (each - x) % abs(a[n - 1]) == 0):
				ans += 1
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	cz = 0
	co = 0
	pb = [0] * (n + 1)
	answer = 0
	for i in range(1, n + 1):
		if s[i - 1] == '0':
			cz += 1
		else:
			co += 1
		pb[i] = cz - co
	if pb[-1] == 0:
		if x in pb:
			print(-1)
		else:
			print(0)
		continue
	end = pb[-1]
	for i in range(n):
		if (x - pb[i]) % end == 0 and (x - pb[i]) // end >= 0:
			answer += 1
	print(answer)


def solve(s, x):
	prefs = [0]
	for c in s:
		prefs.append(prefs[-1] + (1 if c == '0' else -1))
	if prefs[-1] == 0 and x in prefs:
		print(-1)
	elif prefs[-1] == 0:
		print(0)
	else:
		n = 0 if x else 1
		for p in prefs[1:]:
			n += (x - p) % prefs[-1] == 0 and (x - p) * prefs[-1] >= 0
		print(n)
t = int(input())
for _ in range(t):
	(n, x) = (int(_) for _ in input().split())
	s = input().strip()
	solve(s, x)


cases = int(input())
for _ in range(cases):
	(l, n) = list(map(int, input().split()))
	s = input()
	c = 0
	cc = []
	for i in s:
		if i == '1':
			c -= 1
		else:
			c += 1
		cc.append(c)
	if c == 0:
		if n not in cc:
			if n == 0:
				print(1)
			else:
				print(0)
		else:
			print(-1)
	else:
		r = 0
		if n == 0:
			r += 1
		for i in cc:
			k = (n - i) / c
			if k >= 0 and k == int(k):
				r += 1
		print(r)


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, X) = MAP()
	S = input()
	acc = [1 if c == '0' else -1 for c in S]
	acc = [0] + list(accumulate(acc))
	mod = acc[-1]
	acc = acc[:-1]
	if mod > 0:
		cnt = 0
		for a in acc:
			if (X - a) % mod == 0 and X - a >= 0:
				cnt += 1
		print(cnt)
	elif mod < 0:
		cnt = 0
		for a in acc:
			if (X - a) % mod == 0 and X - a <= 0:
				cnt += 1
		print(cnt)
	else:
		for a in acc:
			if a == X:
				print(-1)
				break
		else:
			print(0)


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	t = inin()
	for _ in range(t):
		(n, x) = cin()
		s = sin()
		j = k = 0
		for i in s:
			if i == '0':
				j += 1
			else:
				k += 1
		p = j - k
		f = ans = 0
		an = 0
		for i in s:
			if (j - k) * (x - f) >= 0 and p != 0 and (abs(x - f) % p == 0):
				ans += 1
			if i == '0':
				f += 1
			else:
				f -= 1
			if f == x and p == 0:
				ans = -1
				break
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import atexit
import io
import sys
input = sys.stdin.readline
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	t = input()
	prf = [0] * (n + 1)
	for i in range(n):
		prf[i + 1] = prf[i] + (1 if t[i] == '0' else -1)
	if prf[n] == 0:
		if x in prf:
			print(-1)
		else:
			print(0)
	else:
		res = 0
		for i in prf[:-1]:
			if abs(x - i) % abs(prf[n]) == 0 and (x - i) // prf[n] >= 0:
				res += 1
		print(res)


from collections import Counter
from itertools import accumulate

def go():
	(n, x) = map(int, input().split())
	s = map(int, input())
	a = accumulate(s)
	a = [z - 2 * o for (z, o) in zip(range(1, n + 1), a)]
	c = Counter(a)
	if a[-1] == 0:
		if x in c:
			return -1
		else:
			return 0
	elif a[-1] > 0:
		result = 0 if x != 0 else 1
		for (v, cc) in c.items():
			if v <= x and v % a[-1] == x % a[-1]:
				result += cc
		return result
	elif a[-1] < 0:
		result = 0 if x != 0 else 1
		for (v, cc) in c.items():
			if v >= x and v % a[-1] == x % a[-1]:
				result += cc
		return result
t = int(input())
for _ in range(t):
	print(go())


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, X) = map(int, input().split())
	A = input().rstrip()
	Query.append((N, X, A))
for (N, X, A) in Query:
	tmp = 0
	Max = 0
	Min = 0
	T = [0]
	for a in A:
		if int(a):
			tmp -= 1
		else:
			tmp += 1
		T.append(tmp)
		Max = max(Max, tmp)
		Min = min(Min, tmp)
	cycle = T.pop()
	if cycle == 0:
		ans = 0
		for t in T:
			if t == X:
				ans = -1
				break
	else:
		ans = 0
		for t in T:
			if (t - X) % cycle == 0 and (t - X) // cycle <= 0:
				ans += 1
	print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, x) = li()
	s = st()
	cnt = Counter()
	l = []
	for i in s:
		cnt[i] += 1
		l.append(cnt['0'] - cnt['1'])
	totone = l[-1]
	if not totone and x in set(l):
		print(-1)
		continue
	ans = 0 if x else 1
	if not totone:
		print(0)
		continue
	for j in l:
		if not (x - j) % totone and (x - j) // totone >= 0:
			ans += 1
	print(ans)


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	(n, k) = map(int, input().split())
	s = input()
	x = 0
	d = dd(int)
	for i in s:
		if i == '0':
			x += 1
		else:
			x -= 1
		d[x] += 1
	if x == 0:
		if d[k]:
			print(-1)
		else:
			print(0)
		continue
	c = 0
	if k == 0:
		c = 1
	if x > 0:
		rem = k % x
		for i in d:
			if i <= k and i % x == rem:
				c += d[i]
		print(c)
	else:
		mp = dd(int)
		y = 0
		k = -k
		for i in s:
			if i == '1':
				y += 1
			else:
				y -= 1
			mp[y] += 1
		rem = k % y
		for i in mp:
			if i <= k and i % y == rem:
				c += mp[i]
		print(c)


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	l = [0] * n
	c = 0
	ans = 0
	for j in range(n):
		if s[j] == '0':
			c += 1
		else:
			c -= 1
		l[j] = c
	if s[0] == '0':
		c += 1
	else:
		c -= 1
	inc = c - l[0]
	if x == 0:
		ans += 1
	for j in l:
		if j == x:
			if inc == 0:
				ans = -1
				break
			else:
				ans += 1
		elif x - j < 0 and inc < 0:
			if (x - j) % inc == 0:
				ans += 1
		elif x - j > 0 and inc > 0:
			if (x - j) % inc == 0:
				ans += 1
	print(ans)


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for i in range(int(input())):
	(n, x) = read()
	count = 0
	s = []
	for i in input():
		count += [1, -1][i == '1']
		s.append(count)
	if count == 0:
		if x == 0 or x in s:
			print(-1)
		else:
			print(0)
	else:
		ans = [0, 1][x == 0]
		for i in s:
			if (x - i) % count == 0 and (x - i) // count >= 0:
				ans += 1
		print(ans)


from collections import Counter
T = int(input().strip())
for _ in range(T):
	(n, x) = [int(s) for s in input().strip().split()]
	s = input().strip()
	B = [0] * len(s)
	b = 0
	for (i, c) in enumerate(s):
		b += 1 if c == '0' else -1
		B[i] = b
	if b == 0:
		print(-1 if x in B else 0)
		continue
	result = 0
	if x == 0:
		result += 1
	for v in B:
		if (x - v) % b == 0 and (x - v) // b >= 0:
			result += 1
	print(result)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	s = input()
	count_1 = 0
	count_0 = 0
	curr = 0
	dp = []
	for i in s:
		if i == '0':
			curr += 1
			count_0 += 1
		else:
			curr -= 1
			count_1 += 1
		dp.append(curr)
	if dp[-1] == 0 and x in dp:
		print(-1)
		continue
	count = 0
	if dp[-1] > 0:
		if x >= 0:
			for i in range(n):
				if dp[i] == x:
					count += 1
				elif x > dp[i] and (x - dp[i]) % dp[-1] == 0:
					count += 1
		if x < 0:
			for i in range(n):
				if dp[i] == x:
					count += 1
				elif x > dp[i] and (x - dp[i]) % dp[-1] == 0:
					count += 1
	if dp[-1] < 0:
		if x <= 0:
			for i in range(n):
				if dp[i] == x:
					count += 1
				elif x < dp[i] and (x - dp[i]) % dp[-1] == 0:
					count += 1
		if x > 0:
			for i in range(n):
				if dp[i] == x:
					count += 1
				elif x < dp[i] and (dp[i] - x) % dp[-1] == 0:
					count += 1
	if x == 0:
		print(count + 1)
	else:
		print(count)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for test in range(t):
	(n, x) = map(int, input().split())
	s = input().strip()
	Z = [0]
	for st in s:
		if st == '0':
			Z.append(Z[-1] + 1)
		else:
			Z.append(Z[-1] - 1)
	Z = Z[1:]
	C = Counter(Z)
	change = Z[-1]
	MAX = max(Z)
	MIN = min(Z)
	if change == 0 and MIN <= x <= MAX:
		print(-1)
		continue
	elif change == 0:
		print(0)
		continue
	if x == 0:
		ANS = 1
	else:
		ANS = 0
	if change > 0:
		for i in range(max(0, (x - MAX) // change - 2), (x - MIN) // change + 2):
			ANS += C[x - change * i]
	else:
		for i in range(max(0, (x - MIN) // change - 2), (x - MAX) // change + 2):
			ANS += C[x - change * i]
	print(ANS)


import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def SI():
	return sys.stdin.readline()[:-1]

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def MF():
	return map(float, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LF():
	return list(map(float, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
	inf = 10 ** 9
	t = II()
	for _ in range(t):
		(n, x) = MI()
		cnt = defaultdict(int)
		s = 0
		mx = -inf
		mn = inf
		for c in SI():
			cnt[s] += 1
			if c == '0':
				s += 1
			else:
				s -= 1
			if s > mx:
				mx = s
			if s < mn:
				mn = s
		if s == 0:
			if cnt[x] == 0:
				print(0)
			else:
				print(-1)
			continue
		ans = 0
		start = max(0, min((x - mx) // s, (x - mn) // s) - 3)
		stop = max((x - mx) // s, (x - mn) // s) + 3
		for m in range(start, stop):
			ans += cnt[x - s * m]
		print(ans)
main()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	sl = list(input())
	al = []
	flag = 0
	if x == 0:
		flag = 1
	now = 0
	for s in sl:
		if s == '0':
			now += 1
		else:
			now -= 1
		al.append(now)
	k = al[-1]
	if k == 0:
		if x in al:
			print(-1)
		else:
			print(0 + flag)
	else:
		ans = 0
		for a in al:
			if (x - a) % k == 0 and (x - a) * k >= 0:
				ans += 1
		print(ans + flag)


import sys
q = int(input())
while q:
	(n, x) = map(int, input().split())
	s = input()
	d = {}
	cnt = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
		else:
			cnt -= 1
		d[i] = cnt
	inf = 0
	if x == 0:
		cnt = 1
	else:
		cnt = 0
	for i in d:
		if d[n - 1] == 0:
			if d[i] == x:
				inf = 1
				break
		else:
			if x - d[i] >= 0 and d[n - 1] > 0 and ((x - d[i]) % d[n - 1] == 0):
				cnt += 1
			if x - d[i] <= 0 and d[n - 1] < 0 and ((x - d[i]) % d[n - 1] == 0):
				cnt += 1
	if inf == 1:
		print(-1)
	else:
		print(cnt)
	q -= 1


import math
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s1 = input()
	s = list()
	for i in range(len(s1) - 1):
		s.append(s1[i])
	one = 0
	zero = 0
	l = list()
	for i in range(len(s)):
		if s[i] == '0':
			zero += 1
		else:
			one += 1
		l.append(zero - one)
	if l[-1] == 0:
		flag = 0
		for i in range(len(l)):
			if l[i] == x:
				flag = 1
		if flag:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		if x == 0:
			ans += 1
		for i in range(len(l)):
			curr = (x - l[i]) / l[-1]
			if curr >= 0 and curr == int(curr):
				ans += 1
		print(ans)


def getans():
	(n, x) = map(int, input().split(' '))
	s = input()
	a = []
	for i in s:
		if i == '0':
			a.append(1)
		else:
			a.append(-1)
	b = [a[0]]
	for i in range(1, len(a)):
		b.append(b[-1] + a[i])
	step = b[-1]
	ans = 0
	if x == 0:
		ans = ans + 1
	if step == 0:
		for i in b:
			if x == i:
				return -1
		return ans
	elif step < 0:
		step = -step
		for i in b:
			if i >= x and (i - x) % step == 0:
				ans = ans + 1
	else:
		for i in b:
			if i <= x and (x - i) % step == 0:
				ans = ans + 1
	return ans
t = int(input())
for i in range(t):
	print(getans())


INF = 10 ** 10

def main():
	print = out.append
	(n, x) = get_list()
	prefix = [0]
	for i in input():
		if i == '0':
			prefix.append(prefix[-1] + 1)
		else:
			prefix.append(prefix[-1] - 1)
	prefix = prefix[1:]
	if prefix[-1] == 0:
		if x in prefix:
			res = -1
		else:
			res = 0
	else:
		res = 0 if x != 0 else 1
		for i in prefix:
			if (x - i) % prefix[-1] == 0 and (x - i) // prefix[-1] >= 0:
				res += 1
	print(res)
import sys
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	s = list(map(int, list(input())))
	for (i, num) in enumerate(s):
		s[i] = 1 if num == 0 else -1
	firstlevel = []
	csum = 0
	for i in s:
		csum += i
		firstlevel.append(csum)
	secondlevel = []
	for i in s:
		csum += i
		secondlevel.append(csum)
	m = len(firstlevel)
	ans = 0
	if x == 0:
		ans = 1
	for i in range(m):
		a = firstlevel[i]
		b = secondlevel[i]
		c = b - a
		if a == x:
			if c == 0:
				ans = -1
				break
			else:
				ans += 1
		else:
			difference = x - a
			if difference * c > 0:
				if difference % c == 0:
					ans += 1
	print(ans)


t = int(input())
for ti in range(t):
	(n, x) = map(int, input().split())
	s = input()
	bal = s.count('0') - s.count('1')
	cnt = 0
	ans = 0

	def sit(xc):
		global ans
		if bal == 0:
			if xc == 0:
				ans = -1
		elif xc % bal == 0:
			if xc // bal >= 0:
				ans += 1
	for c in s:
		sit(x - cnt)
		if c == '0':
			cnt += 1
		else:
			cnt -= 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	(n, x) = map(int, input().split())
	s = input()
	bal = [0]
	mx = 0
	mn = float('inf')
	for c in s:
		if c == '0':
			bal.append(bal[-1] + 1)
		else:
			bal.append(bal[-1] - 1)
		mx = max(mx, bal[-1])
		mn = min(mn, bal[-1])
	if bal[-1] == 0:
		if x in bal:
			print(-1)
		else:
			print(0)
		return
	cnt = 0
	gain = bal[-1]
	bal = bal[1:]
	if x == 0:
		cnt += 1
	for el in bal:
		if (x - el) % gain == 0 and (x - el) // gain >= 0:
			cnt += 1
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	a = input().split(' ')
	n = int(a[0])
	x = int(a[1])
	a = input()
	values = []
	curr = 0
	for i in range(len(a)):
		if a[i] == '0':
			curr = curr + 1
			values.append(curr)
		else:
			curr = curr - 1
			values.append(curr)
	diff = values[-1]
	if diff == 0:
		count = 0
		for i in range(len(values)):
			if values[i] == x:
				count = 1
				break
		if count == 1:
			print(-1)
		else:
			print(0)
		continue
	maxval = max(values)
	minval = min(values)
	count = 0
	if x == 0:
		count = 1
	if diff < 0:
		for i in range(len(values)):
			if values[i] > x:
				if (values[i] - x) % diff == 0:
					count = count + 1
			elif values[i] == x:
				count = count + 1
	else:
		for i in range(len(values)):
			if values[i] < x:
				if (x - values[i]) % diff == 0:
					count = count + 1
			elif values[i] == x:
				count = count + 1
	print(count)


bestNum = {2: 1, 3: 7, 4: 7, 5: 7, 6: 9, 7: 9}
ans = []
for t in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	s = input()
	currBal = 0
	pSum = []
	for i in s:
		if i == '0':
			currBal += 1
		else:
			currBal -= 1
		pSum.append(currBal)
	count = 0
	n -= 1
	if pSum[n] != 0:
		l = 0
		for i in pSum:
			temp = x - i
			div = temp % pSum[n]
			if temp == 0 or (pSum[n] > 0 and temp > 0 and (div == 0)) or (pSum[n] < 0 and temp < 0 and (div == 0)):
				count += 1
			l += 1
	else:
		for i in pSum:
			temp = x - i
			if temp == 0:
				count += 1
	a = count
	if a > 0 and pSum[n] == 0:
		a = -1
	elif x == 0:
		a += 1
	ans.append(str(a))
print('\n'.join(ans))


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	s = input()
	arr = [0]
	for i in range(len(s)):
		val = 1
		if s[i] == '1':
			val = -1
		arr.append(arr[-1] + val)
	base = arr[-1]
	if base == 0:
		found = False
		for i in range(len(arr)):
			if arr[i] == x:
				found = True
				break
		if found:
			print(-1)
		else:
			print(0)
		continue
	neg = base < 0
	rv = 0
	if 0 == x:
		rv += 1
	arr.pop(0)
	foo = x % abs(base)
	for i in range(len(arr)):
		if neg:
			if arr[i] >= x and arr[i] % abs(base) == foo:
				rv += 1
		elif arr[i] <= x and arr[i] % abs(base) == foo:
			rv += 1
	print(rv)


class Solution(object):

	def __init__(self):
		pass

	def apply(self, s, x):
		b = 0
		prefix = []
		for c in s:
			if c == '1':
				b -= 1
			else:
				b += 1
			prefix.append(b)
		s = 0
		for nm in prefix:
			if b == 0:
				if nm == x:
					return -1
			elif (x - nm) % b == 0 and (x - nm) * b >= 0:
				s += 1
		if x == 0:
			s += 1
		return s

def main():
	sol = Solution()
	t = int(input())
	for i in range(t):
		info = input().split()
		n = int(info[0])
		x = int(info[1])
		s = input()
		print(sol.apply(s, x))
	return 0
main()


for _ in range(int(input())):
	(n, X) = [int(x) for x in input().split()]
	arr = input()
	asum = [0]
	for i in range(n):
		asum.append(asum[-1] + (1 if arr[i] == '0' else -1))
	if asum[-1] == 0:
		if X in asum:
			print(-1)
		else:
			print(0)
		continue
	else:
		total = 0
		for i in range(1, n + 1):
			if (X - asum[i]) % asum[-1] == 0 and (X - asum[i]) // asum[-1] >= 0:
				total += 1
		if X == 0:
			total += 1
	print(total)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	c0 = 0
	c1 = 0
	posl = []
	for j in s:
		if j == '0':
			c0 += 1
		else:
			c1 += 1
		xn = c0 - c1
		posl.append(xn)
	if c1 == 0:
		if x >= 0:
			print(1)
		else:
			print(0)
	elif c0 == 0:
		if x <= 0:
			print(1)
		else:
			print(0)
	else:
		d = posl[-1]
		if d == 0:
			if x in posl:
				print(-1)
			else:
				print(0)
		else:

			def check(point, line, delta):
				if point <= line and delta > 0:
					r = True
				elif point >= line and delta < 0:
					r = True
				else:
					r = False
				return r
			summ = 0
			if x == 0:
				summ += 1
			for p in posl:
				if check(p, x, d):
					if x == p or abs(x - p) % abs(d) == 0:
						summ += 1
			print(summ)


import math
t = int(input())
from collections import Counter
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	pre = [0]
	cnt = 0
	ans = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
		else:
			cnt -= 1
		pre.append(cnt)
	var = pre[-1]
	if var == 0:
		if x in pre:
			print(-1)
		else:
			print(0)
	else:
		for i in range(n):
			if (x - pre[i]) % pre[-1] == 0 and (x - pre[i]) // pre[-1] >= 0:
				ans += 1
		print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, list(input())))
	prev = 0
	bal = [0 for i in range(n)]
	ans = 0
	s = n - 2 * sum(a)
	for i in range(n):
		if a[i] == 0:
			prev += 1
		else:
			prev -= 1
		bal[i] = prev
		if s == 0:
			if x == bal[i]:
				ans = -1
				break
		elif (x - bal[i]) % s == 0 and (x - bal[i]) // s >= 0:
			ans += 1
	if x == 0 and ans != -1:
		ans += 1
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

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

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(n, k) = mp()
	s = inp()
	c = 0
	cnt = []
	for i in s:
		if i == '0':
			c += 1
		else:
			c -= 1
		cnt.append(c)
	if c == 0:
		print(-1 if k in cnt else 0)
	elif c > 0:
		x = k % c
		ans = 0 if k != 0 else 1
		for i in cnt:
			if i <= k and i % c == x:
				ans += 1
		print(ans)
	else:
		x = k % c
		ans = 0 if k != 0 else 1
		for i in cnt:
			if i >= k and i % c == x:
				ans += 1
		print(ans)


from math import *
import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(input().rstrip())
	cnt = [0 for i in range(n + 1)]
	for i in range(1, n + 1):
		if a[i - 1] == '0':
			cnt[i] = cnt[i - 1] + 1
		else:
			cnt[i] = cnt[i - 1] - 1
	if cnt[n] == 0 and x == 0:
		print(-1)
		continue
	c = int(x == 0)
	flag = 0
	for i in range(1, n + 1):
		if x - cnt[i] == 0:
			if cnt[n] == 0:
				flag = 1
				break
			c += 1
	if flag:
		print(-1)
		continue
	for i in range(1, n + 1):
		if cnt[n] == 0:
			break
		if (x - cnt[i]) % cnt[n] == 0 and (x - cnt[i]) // cnt[n] > 0:
			c += 1
	print(c)


from math import *
t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	s = input()
	ref = []
	(z, o) = (0, 0)
	for i in s:
		if i == '0':
			z += 1
			ref.append(z - o)
		else:
			o += 1
			ref.append(z - o)
	ref1 = []
	s1 = 0
	if x == 0:
		s1 += 1
	flag = 0
	for i in s:
		if i == '0':
			z += 1
			ref1.append(z - o)
		else:
			o += 1
			ref1.append(z - o)
	di = ref1[0] - ref[0]
	for i in range(n):
		f = x - ref[i]
		if di != 0:
			f = f / di
		if ceil(f) == floor(f) and di != 0:
			f = f + 1
			if f > 0:
				s1 += 1
		if di == 0 and x == ref[i]:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		print(s1)


T = int(input())
for _ in range(T):
	(n, x) = [int(l) for l in input().split()]
	arr = [0] * n
	s = input()
	sm = 0
	ans = 0
	for i in range(n):
		if s[i] == '0':
			sm += 1
		else:
			sm -= 1
		if sm == x:
			ans += 1
		arr[i] = sm
	if sm == 0 and ans != 0:
		print(-1)
	elif sm == 0 and ans == 0:
		print(ans)
	else:
		ans = 0
		for i in range(n):
			k = (x - arr[i]) // sm
			if k >= 0 and k * sm + arr[i] == x:
				ans += 1
		if x == 0:
			ans += 1
		print(ans)


def solve():
	(n, x) = [int(v) for v in input().split()]
	s = input()
	cnt1 = 0
	cnt0 = 0
	diff = 0
	values = {}
	for i in range(n):
		if s[i] == '1':
			cnt1 += 1
		else:
			cnt0 += 1
		diff = cnt0 - cnt1
		values.setdefault(diff, 0)
		values[diff] += 1
	if not diff:
		if x in values:
			print(-1)
		elif x == 0:
			print(1)
		else:
			print(0)
		return
	ans = 0
	for v in values:
		if v == x:
			ans += values[v]
		if (x - v) % diff == 0 and (x - v) / diff > 0:
			ans += values[v]
	if x == 0:
		ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	z = 0
	ans = int(x == 0)
	seg = s.count('0') - s.count('1')
	can = True
	for i in s:
		z += 1 if i == '0' else -1
		if seg == 0 and z == x:
			can = False
			ans = -1
			break
		elif z == x or ((x - z) * seg > 0 and (x - z) % seg == 0):
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	r = 0
	cnt = 0
	q = []
	if x == 0:
		cnt = cnt + 1
	for i in range(n):
		if s[i] == '0':
			r = r + 1
		else:
			r = r - 1
		q.append(r)
	for i in range(n):
		if q[i] == x and q[-1] == 0:
			cnt = -1
			break
		if q[-1] != 0:
			if (x - q[i]) * q[-1] >= 0 and (x - q[i]) % q[-1] == 0:
				cnt = cnt + 1
	print(cnt)


t = input()
t = int(t)
for i in range(t):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	s = input()
	balance = []
	ans = 0
	if x == 0:
		ans = 1
	if int(s[0]) == 1:
		balance.append(-1)
	else:
		balance.append(1)
	for j in range(n - 1):
		if int(s[j + 1]) == 0:
			balance.append(balance[j] + 1)
		else:
			balance.append(balance[j] - 1)
	total = balance[n - 1]
	if total == 0:
		if balance.count(x):
			print('-1')
		else:
			print(0)
	elif total < 0:
		for k in range(n):
			if balance[k] - x >= 0 and (balance[k] - x) % (-1 * total) == 0:
				ans += 1
		print(ans)
	else:
		for k in range(n):
			if balance[k] - x <= 0 and (balance[k] - x) % total == 0:
				ans += 1
		print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	data = input()
	now = 0
	temp = [0] * n
	for i in range(n):
		if data[i] == '0':
			now += 1
		else:
			now -= 1
		temp[i] = now
	if temp[n - 1] == 0:
		if min(temp) <= x and x <= max(temp):
			print(-1)
			continue
		else:
			print(0)
			continue
	count = 0
	if x == 0:
		count += 1
	b = temp[n - 1]
	for a in temp:
		if x == a:
			count += 1
			continue
		if (x - a > 0) == (b > 0) and (x - a) % b == 0:
			count += 1
	print(count)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	count0 = 0
	l = []
	for j in range(n):
		if s[j] == '0':
			count0 += 1
			l.append(count0)
		else:
			count0 -= 1
			l.append(count0)
	a = s.count('0')
	b = len(s) - a
	k = a - b
	if a == b and x == 0:
		print(-1)
	elif a == b and x in l:
		print(-1)
	elif a == b and x not in l:
		print(0)
	else:
		flag = 0
		for j in l:
			c = (x - j) / k
			if c == int(c) and c >= 0:
				flag += 1
		if x == 0:
			print(flag + 1)
		else:
			print(flag)


T = int(input())
for o in range(T):
	(n, d) = map(int, input().split())
	s = input()
	num = [0] * (2 * n + 1)
	now = 0
	for i in s:
		if i == '0':
			num[now + n] += 1
			now += 1
		elif i == '1':
			num[now + n] += 1
			now -= 1
	if now == 0:
		if d <= n and d >= -n and (num[d + n] > 0):
			print(-1)
		else:
			print(0)
	elif d > n and now < 0 or (d < -n and now > 0):
		print(0)
	elif d > n or d < -n:
		ans = 0
		if now < 0:
			now = -now
		d %= now
		d = (d + now) % now
		for i in range(-n, n):
			if (i % now + now) % now == d:
				ans += num[i + n]
		print(ans)
	else:
		ans = 0
		while d >= -n and d <= n:
			ans += num[d + n]
			d -= now
		print(ans)


import sys
input = sys.stdin.readline
from itertools import accumulate

def solve():
	(n, x) = map(int, input().split())
	s = input().strip()
	init = list(accumulate([-1 if i == '1' else 1 for i in s]))
	count = 0
	if init[-1] == 0:
		if x in init:
			print(-1)
			return
		else:
			print(0)
			return
	for i in init:
		if (x - i) % init[-1] == 0:
			if (x - i) // init[-1] >= 0:
				count += 1
	if x == 0:
		count += 1
	print(count)
for _ in range(int(input())):
	solve()


def solve():
	(n, x) = [int(v) for v in input().split()]
	s = input()
	cnt1 = 0
	cnt0 = 0
	ans = 0
	tdiff = s.count('0') - s.count('1')
	foundx = False
	for i in range(n):
		if s[i] == '1':
			cnt1 += 1
		else:
			cnt0 += 1
		diff = cnt0 - cnt1
		if x == diff:
			ans += 1
			foundx = True
		if tdiff != 0 and (x - diff) % tdiff == 0 and ((x - diff) / tdiff > 0):
			ans += 1
	if x == 0:
		ans += 1
	if not tdiff:
		if foundx:
			print(-1)
		elif x == 0:
			print(1)
		else:
			print(0)
	else:
		print(ans)
t = int(input())
for _ in range(t):
	solve()


def problem(n, x, s):
	r = 1 if x == 0 else 0
	t = sum(s)
	y = 0
	for i in s:
		y += i
		if y == x:
			if t == 0:
				return -1
			r += 1
		elif (x - y) * t > 0 and (x - y) % t == 0:
			r += 1
	return r
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(map(lambda i: 1 if i == '0' else -1, input()))
	print(problem(n, x, s))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	(n, X) = inpl()
	s = list(sys.stdin.readline())
	s = s[:n]
	cnt = [-1] * n
	now = 0
	for (i, x) in enumerate(s):
		if x == '0':
			now += 1
		else:
			now -= 1
		cnt[i] = now
	las = now
	if las == 0:
		if X == 0 or cnt.count(X):
			print(-1)
		else:
			print(0)
		continue
	res = 0
	for (i, x) in enumerate(cnt):
		now = X - x
		if now * las < 0:
			continue
		if abs(now) % abs(las) == 0:
			res += 1
	if X == 0:
		res += 1
	print(res)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	b = list()
	if s[0] == '1':
		b.append(-1)
	else:
		b.append(1)
	for i in range(1, n):
		if s[i] == '1':
			b.append(b[-1] - 1)
		else:
			b.append(b[-1] + 1)
	ans = 0
	k = b[-1]
	if x == 0:
		ans += 1
	if k > 0:
		for i in range(n):
			if b[i] % k == x % k and b[i] <= x:
				ans += 1
	elif k == 0:
		for i in range(n):
			if b[i] == x:
				ans = -1
				break
	else:
		for i in range(n):
			if b[i] % -k == x % -k and b[i] >= x:
				ans += 1
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

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

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 zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

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

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
from bisect import bisect_left
from random import randint
from itertools import groupby
from collections import defaultdict
Max = 10 ** 6 + 5
N = 10 ** 9 + 7

def solve():
	t = int(input())
	for _ in range(t):
		(n, x) = sep()
		c0 = 0
		c1 = 0
		s = input()
		ar = []
		for i in range(n):
			if s[i] == '1':
				c1 += 1
			else:
				c0 += 1
			ar.append(c0 - c1)
		k = ar[n - 1]
		if k == 0:
			t = 0
			for i in ar:
				if i == x:
					t = 1
					break
			if t == 1:
				print(-1)
			else:
				print(0)
			continue
		ans = 0
		for i in range(n):
			if (x - ar[i]) % k == 0 and (x - ar[i]) // k >= 0:
				ans += 1
		if x == 0:
			ans += 1
		print(ans)
solve()


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	diff = []
	c0 = 0
	c1 = 0
	ans = 0
	for j in range(n):
		if s[j] == '0':
			c0 += 1
		else:
			c1 += 1
		diff.append(c0 - c1)
	if diff[n - 1] == 0:
		if x in diff:
			print(-1)
		else:
			print(0)
	else:
		denom = diff[n - 1]
		for j in range(n):
			k = (x - diff[j]) / denom
			if int(k) - k == 0 and k >= 0:
				ans += 1
		if x == 0:
			ans += 1
		print(ans)


import os
import sys
from atexit import register
from io import StringIO
sys.stdout = StringIO()
register(lambda : os.write(1, sys.stdout.getvalue().encode()))

def sign(n):
	if n > 0:
		return 1
	elif n < 0:
		return -1
	else:
		return 0
T = int(input())
for _ in range(T):
	[n, x] = [int(k) for k in input().split()]
	s = input()
	balances = {}
	b = 0
	for c in s:
		b += 1 if c == '0' else -1
		if b not in balances:
			balances[b] = 0
		balances[b] += 1
	if b == 0:
		print(-1 if x in balances else 0)
	else:
		ret = 0
		if x == 0:
			ret += 1
		for k in balances:
			if (x - k) % b == 0 and sign(x - k) == sign(b):
				ret += balances[k]
			elif x == k:
				ret += balances[k]
		print(ret)


from sys import stdin

def inp():
	return (ss.rstrip() for ss in stdin).__next__()

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

def cnt(ss):
	return ss.count('0') * 2 - len(ss)
for case in range(int(inp())):
	(n, x) = mpint()
	s = inp()
	cnt = 0
	prefix = []
	for c in s:
		if c == '0':
			cnt += 1
		else:
			cnt -= 1
		prefix.append(cnt)
	if s[0] == '0':
		cnt += 1
	else:
		cnt -= 1
	cnt = cnt - prefix[0]
	ans = 1 if x == 0 else 0
	if cnt == 0:
		if x in prefix:
			print(-1)
		else:
			print(ans)
	else:
		for k in prefix:
			if x == k or ((x - k) % cnt == 0 and (x - k) / cnt > 0):
				ans += 1
		print(ans)


from random import *
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	calc = []
	t = 0
	for i in range(n):
		if s[i] == '0':
			t += 1
		else:
			t -= 1
		calc.append(t)
	if calc[-1] == 0:
		if x in calc:
			print(-1)
		else:
			print(0)
	else:
		ans = int(x == 0)
		for i in range(n):
			if (x - calc[i]) * calc[-1] >= 0 and abs(x - calc[i]) % abs(calc[-1]) == 0:
				ans += 1
		print(ans)


T = int(input())
for i in range(T):
	(n, x) = map(int, input().split())
	s = str(input())
	l = [0] * n
	l[0] = 1 - 2 * int(s[0])
	for j in range(1, n):
		if s[j] == '0':
			l[j] = l[j - 1] + 1
		else:
			l[j] = l[j - 1] - 1
	tmp = l[-1]
	ans = 0
	if x == 0:
		ans = 1
	if tmp != 0:
		for j in range(n):
			if (x - l[j]) % tmp == 0 and (x - l[j]) * tmp >= 0:
				ans += 1
		print(ans)
	else:
		flag = True
		for j in range(n):
			if x - l[j] == 0:
				flag = False
				print(-1)
				break
		if flag:
			print(ans)


import sys
t_ = int(input())
while t_:
	t_ -= 1
	(n, x) = map(int, input().split())
	s = input().strip()
	(o, z) = (0, 0)
	for i in s:
		if i == '1':
			o += 1
		else:
			z += 1
	maxx = z - o
	bal = ans = 0
	for i in s:
		if maxx == 0:
			if bal == x:
				ans = -1
				break
		elif (x - bal) % maxx == 0 and (x - bal) // maxx >= 0:
			ans += 1
		if i == '0':
			bal += 1
		else:
			bal -= 1
	print(ans)


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(input())
	pre = [[0, 0] for i in range(n + 3)]
	dif = [0] * n
	for i in range(n):
		if s[i] == '0':
			pre[i][0] = pre[i - 1][0] + 1
			pre[i][1] = pre[i - 1][1]
		else:
			pre[i][0] = pre[i - 1][0]
			pre[i][1] = pre[i - 1][1] + 1
		dif[i] = pre[i][0] - pre[i][1]
	add = dif[-1]
	ans = 0
	c = 1
	if x == 0:
		ans += 1
	for i in range(n):
		if add == 0 and dif[i] == x:
			print(-1)
			c = 0
			break
		if add != 0 and (x - dif[i]) % add == 0 and ((x - dif[i]) / add >= 0):
			ans += 1
	if c:
		print(ans)


def get_balance_vec(s):
	balance_vec = [0] * (len(s) + 1)
	for i in range(len(s)):
		if s[i] == '0':
			balance_vec[i + 1] = balance_vec[i] + 1
		else:
			balance_vec[i + 1] = balance_vec[i] - 1
	return balance_vec

def num_of_prefixes(x, s):
	balance_vec = get_balance_vec(s)
	if balance_vec[-1] == 0:
		for i in range(len(s)):
			if balance_vec[i] == x:
				return -1
		return 0
	else:
		count = 0
		for i in range(len(s)):
			if (x - balance_vec[i]) % balance_vec[-1] == 0 and (x - balance_vec[i]) / balance_vec[-1] >= 0:
				count += 1
		return count

def check_balance():
	t = int(input())
	for i in range(t):
		n_x = input().split()
		s = input()
		print(num_of_prefixes(int(n_x[1]), s))
check_balance()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	b = []
	s = input()
	for j in s:
		b.append(int(j))
	p = b.count(0) - b.count(1)
	if p == 0:
		c = []
		j = 0
		s = 0
		while j < n:
			if b[j] == 0:
				s += 1
			else:
				s += -1
			c.append(s)
			j += 1
		if x in c:
			print(-1)
		else:
			print(0)
	else:
		j = 0
		s = 0
		if x == 0:
			ans = 1
		else:
			ans = 0
		while j < n:
			if b[j] == 0:
				s += 1
			else:
				s += -1
			if (x - s) % p == 0 and (x - s) // p >= 0:
				ans += 1
			j += 1
		print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	ans = 0
	if x == 0:
		ans += 1
	count = [0] * (n * 2 + 5)
	c = 0
	for i in range(n):
		if s[i] == '0':
			c += 1
		else:
			c -= 1
		count[c] += 1
	if c == 0 and x == 0:
		print(-1)
	elif c == 0:
		if -n <= x <= n:
			if count[x] > 0:
				print(-1)
			else:
				print(0)
		else:
			print(0)
	else:
		if c > 0:
			if x > n:
				x -= (x - n - 1) // c * c + c
			while -n <= x <= n:
				ans += count[x]
				x -= c
		else:
			if x < -n:
				x += (-n - x - 1) // -c * -c - c
			while -n <= x <= n:
				ans += count[x]
				x -= c
		if x == 0:
			ans += 1
		print(ans)


from collections import Counter
from sys import stdin

def main():

	def solve():
		(n, x) = map(int, input().split())
		ss = input()
		if ss[0] == '0':
			b = [1]
		else:
			b = [-1]
		for s in ss[1:]:
			b.append(b[-1] + (1 if s == '0' else -1))
		bc = Counter(b)
		inc = b[-1]
		if inc == 0:
			if bc[x] != 0:
				print(-1)
			else:
				print(0)
			return
		count = 0
		if x < -n and inc > 0 or (x > n and inc < 0):
			print(0)
			return
		if inc > 0:
			if x > n:
				x = x + (-x + n) // inc * inc
			for i in range(x, -n - 1, -inc):
				count += bc[i]
		else:
			if x < -n:
				x = x + (-x - n) // inc * inc
			for i in range(x, n + 1, -inc):
				count += bc[i]
		if x == 0:
			count += 1
		print(count)
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
while t:
	t -= 1
	(n, x) = list(map(int, input().split()))
	a = input()
	total = a.count('0') - a.count('1')
	count = [0, 0]
	if total == 0:
		ans = 0
		for i in range(n):
			count[int(a[i])] += 1
			if x == count[0] - count[1]:
				ans += 1
		if ans:
			print(-1)
		else:
			print(0)
		continue
	ans = int(x % total == 0 and x // total >= 0)
	for i in range(n - 1):
		count[int(a[i])] += 1
		temp = x - (count[0] - count[1])
		if temp % total == 0 and temp // total >= 0:
			ans += 1
	print(ans)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	s = input()
	tot = s.count('0') - s.count('1')
	bal = 0
	ans = 0
	inff = False
	for j in range(len(s)):
		if tot == 0:
			if bal == x:
				inff = True
				break
		elif abs(x - bal) % tot == 0:
			if (x - bal) / tot >= 0:
				ans += 1
		if s[j] == '0':
			bal += 1
		else:
			bal -= 1
	if inff:
		print(-1)
		continue
	print(ans)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	y = 0
	k = []
	f = 0
	z = s.count('0') - s.count('1')
	cnt = 0
	for i in s:
		if i == '0':
			y += 1
		else:
			y += -1
		k.append(y)
	if z == 0:
		if x not in k:
			if x == 0:
				print(1)
			else:
				print(0)
		else:
			print(-1)
	else:
		if x == 0:
			cnt += 1
		for i in k:
			if (x - i) / z == int((x - i) / z) and (x - i) / z >= 0:
				cnt += 1
		print(cnt)


import sys
input = sys.stdin.readline
t = int(input())
for _ in [0] * t:
	(n, x) = map(int, input().split())
	res = 0
	if x == 0:
		res += 1
	s = list(input())
	b = [0] * n
	for i in range(n):
		if s[i] == '0':
			b[i] = b[i - 1] + 1
		else:
			b[i] = b[i - 1] - 1
	r = b[-1] - b[0]
	if s[0] == '0':
		r += 1
	else:
		r -= 1
	if r == 0:
		for e in b:
			if e == x:
				res = -1
	else:
		for e in b:
			if e < x and r > 0:
				if (x - e) % r == 0:
					res += 1
			elif e > x and r < 0:
				if (e - x) % abs(r) == 0:
					res += 1
			elif e == x:
				res += 1
	print(res)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	(n, x) = rinput()
	s = input()
	prefix = [1 if s[0] == '0' else -1]
	for i in range(1, n):
		temp = 1 if s[i] == '0' else -1
		prefix.append(prefix[i - 1] + temp)
	else:
		overall = prefix[n - 1]
		ans = 0
		if x == 0:
			ans += 1
		for i in range(n):
			if overall == 0:
				if x - prefix[i] == 0:
					ans = -1
					break
			elif (x - prefix[i]) % overall == 0:
				if (x - prefix[i]) // overall >= 0:
					ans += 1
		print(ans)


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

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

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def atoi(s):
	return ord(s) - ord('a')

def inc(s, n=1):
	return chr((ord(s) - ord('a') + n) % 26 + ord('a'))

class XY:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def rotate(a, b, c):
	ang = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)
	if ang == 0:
		return 0
	else:
		return ang / abs(ang)
for _ in range(iinp()):
	(n, x) = mp()
	s = inp()
	b = s.count('0') - s.count('1')
	(c0, c1) = (0, 0)
	bl = l1d(n + 1, 0)
	for i in range(1, n + 1):
		if s[i - 1] == '0':
			c0 += 1
		else:
			c1 += 1
		bl[i] = c0 - c1
	cnt = 0
	if b == 0:
		if x in bl:
			print(-1)
		else:
			print(0)
	else:
		cnt = 0
		for i in bl[:n]:
			if (x - i) % b == 0 and (x - i) // b >= 0:
				cnt += 1
		print(cnt)


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(n, x) = [int(s) for s in input().split()]
		s = input().strip()
		count = [0, 0]
		ans = [0] * (n + 1)
		for i in range(1, n + 1):
			count[int(s[i - 1])] += 1
			ans[i] = count[0] - count[1]
		an = 0
		if x in ans and ans[n] == 0:
			print(-1)
		elif x not in ans and ans[n] == 0:
			print(0)
		else:
			for i in range(n):
				w = x - ans[i]
				if w * ans[n] >= 0:
					if w % ans[n] == 0:
						an += 1
			print(an)
main()


import sys
t = int(input())
g = sys.stdin.readlines()
for i in range(t):
	(n, x) = map(int, g[2 * i].split())
	s = g[2 * i + 1]
	cz = 0
	co = 0
	pb = [0] * (n + 1)
	answer = 0
	for i in range(1, n + 1):
		if s[i - 1] == '0':
			cz += 1
		else:
			co += 1
		pb[i] = cz - co
	if pb[-1] == 0:
		if x in pb:
			print(-1)
		else:
			print(0)
		continue
	end = pb[-1]
	for i in range(n):
		if (x - pb[i]) % end == 0 and (x - pb[i]) // end >= 0:
			answer += 1
	print(answer)


import math

def calc(s):
	cou = [0] * (len(s) + 1)
	for j in range(1, len(s) + 1):
		if s[j - 1] == '1':
			cou[j] = cou[j - 1] - 1
		else:
			cou[j] = cou[j - 1] + 1
	return cou
for i in range(int(input())):
	(n, b) = map(int, input().split())
	s = input()
	r = calc(s)
	ans = 0
	if r[n] == 0:
		t = 0
		for j in range(n):
			if b == r[j]:
				t = 1
		if t == 1:
			print(-1)
		else:
			print(0)
		continue
	for j in range(n):
		if (b - r[j]) % r[n] == 0 and (b - r[j]) / r[n] >= 0:
			ans += 1
	print(ans)


def solve_step3(res, test, balance, keys):
	(mi, ma) = (min(keys), max(keys))
	goal = test[1]
	if balance > 0:
		if goal > ma:
			goal -= balance * ((goal - ma) // balance)
			if goal > ma:
				goal -= balance
		sum1 = 0
		while goal >= mi:
			sum1 += res[goal]
			goal -= balance
		print(sum1)
	else:
		if goal < mi:
			goal -= balance * ((goal - mi) // balance)
			if goal < mi:
				goal -= balance
		sum1 = 0
		while goal <= ma:
			sum1 += res[goal]
			goal -= balance
		print(sum1)

def solve_step2(res, test, balance):
	goal = test[1]
	keys = [i for i in res.keys() if res[i] > 0]
	if balance == 0:
		if goal in keys:
			print('-1')
		else:
			print('0')
		return
	else:
		solve_step3(res, test, balance, keys)

def solve_step1(test):
	string = test[0]
	length = len(string)
	possibles = {i: (False, 0) for i in range(-1 * length, length + 1)}
	sum1 = 0
	for i in range(length):
		possibles[sum1] = (True, possibles[sum1][1] + 1)
		num = int(string[i])
		sum1 += pow(-1, num)
	res = {i: possibles[i][1] for i in possibles}
	solve_step2(res, test, sum1)

def handle_tests():
	number_of_tests = int(input())
	tests = []
	for i in range(number_of_tests):
		(n, x) = input().split()
		string = input()
		tests.append((string, int(x)))
	for test in tests:
		solve_step1(test)
handle_tests()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	balance = 0
	arr = [0]
	for c in input():
		if c == '0':
			balance += 1
		else:
			balance -= 1
		arr.append(balance)
	if balance:
		count = 0
		for val in arr[:-1]:
			if (x - val) % balance == 0 and (x - val) * balance >= 0:
				count += 1
		print(count)
	elif x in arr:
		print(-1)
	else:
		print(0)


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
	(N, X) = map(int, readline().split())
	table = [0] * (2 * N + 3)
	cnt = 0
	S = list(map(int, readline().strip()))
	for s in S:
		cnt += -1 if s else 1
		table[cnt] += 1
	if cnt == 0:
		table[0] += 1
		if -N <= X <= N and table[X]:
			Ans[qu] = -1
		else:
			Ans[qu] = 0
		continue
	elif cnt > 0:
		ans = 0 if X else 1
		if N < X:
			k = -((N - X) // cnt)
			X -= k * cnt
		while -N <= X:
			if N < X:
				X -= cnt
				continue
			ans += table[X]
			X -= cnt
	else:
		ans = 0 if X else 1
		if X < -N:
			k = -((-X - N) // cnt)
			X -= k * cnt
		while X <= N:
			if X < -N:
				X -= cnt
				continue
			ans += table[X]
			X -= cnt
	Ans[qu] = ans
print('\n'.join(map(str, Ans)))


from sys import stdin
t = int(stdin.readline().strip())
for tt in range(t):
	(n, m) = map(int, stdin.readline().strip().split())
	s = stdin.readline().strip()
	bal = 0
	men = 0
	may = 0
	cnt = 0
	arr = [0 for i in range(n + 10)]
	arr1 = [0 for i in range(n + 10)]
	for i in range(n):
		if s[i] == '0':
			bal += 1
		else:
			bal -= 1
		if bal >= 0:
			arr[bal] += 1
		else:
			arr1[-bal] += 1
		if bal == m:
			cnt += 1
	ans = 0
	if cnt > 0 and bal == 0:
		print(-1)
		continue
	if cnt == 0 and bal == 0:
		print(0)
		continue
	for i in range(n + 10):
		dif = m - i
		if dif % bal == 0 and bal * dif >= 0:
			ans += arr[i]
	for i in range(1, n + 10):
		dif = m + i
		if dif % bal == 0 and bal * dif >= 0:
			ans += arr1[i]
	if m == 0:
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	pref = [0] * n
	pref[0] = 1 if s[0] == '0' else -1
	x_found = 0
	for i in range(n):
		if i > 0:
			pref[i] += pref[i - 1] + (1 if s[i] == '0' else -1)
		if pref[i] == x:
			x_found += 1
	last = pref[-1]
	if last == 0:
		if x_found:
			print(-1)
		else:
			print(0)
		continue
	ans = x_found + (1 if x == 0 else 0)
	for i in pref:
		if (x - i) % last == 0:
			if (x - i) // last > 0:
				ans += 1
	print(ans)


def calculate_prefixes(s, x):
	new_s = [-1 if value == 1 else 1 for value in s]
	balance = [0] * len(s)
	current_balance = 0
	for (i, val) in enumerate(new_s):
		current_balance += val
		balance[i] = current_balance
	sum_balance = balance[-1]
	if sum_balance == 0:
		if x in balance:
			return -1
		else:
			return 0
	res = 0
	for value in balance:
		if (x - value) % sum_balance == 0 and (x - value) // sum_balance >= 0:
			res += 1
	if x == 0:
		res += 1
	return res
T = int(input())
results = [0] * T
for i in range(T):
	(s_len, x) = map(int, input().split())
	s = list(map(int, list(input())))
	results[i] = calculate_prefixes(s, x)
for result in results:
	print(result)


t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	a = list((-1 if int(i) else 1 for i in input()))
	s = [0] * n
	s[0] = a[0]
	for i in range(1, n):
		s[i] = s[i - 1] + a[i]
	if s[-1] == 0:
		if x in s:
			print(-1)
		else:
			print(0)
	else:
		res = 1 if x == 0 else 0
		for i in range(n):
			gap = x - s[i]
			if gap % s[-1] == 0 and gap // s[-1] >= 0:
				res += 1
		print(res)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	s = input()
	j = 0
	mi = 2 * n + 10
	A = [0] * (4 * n + 20)
	xx = x
	for k in range(n):
		if s[k] == '1':
			j -= 1
		else:
			j += 1
		A[j + mi] += 1
	ans = 0
	if j != 0:
		if x >= n + 2 and j > 0:
			x = n + 2 + (x - n - 2) % j
		elif x <= -n - 2 and j < 0:
			x = -n - 2 + (x + n + 2) % abs(j) + j
		s = x + mi
		while 0 <= s < len(A):
			ans += A[s]
			s -= j
	elif 0 <= x + mi < len(A) and A[x + mi] > 0:
		ans = -1
	else:
		ans = 0
	if ans != -1 and xx == 0:
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = [int(i) for i in input().strip()]
	base_score = s.count(0) - s.count(1)
	pf_zero = [0] * n
	pf_one = [0] * n
	if s[0]:
		pf_one[0] = 1
	else:
		pf_zero[0] = 1
	for i in range(1, n):
		pf_one[i] = pf_one[i - 1]
		pf_zero[i] = pf_zero[i - 1]
		if s[i]:
			pf_one[i] += 1
		else:
			pf_zero[i] += 1
	mods = [pf_zero[i] - pf_one[i] for i in range(n)]
	if base_score == 0:
		if x in mods:
			print(-1)
		else:
			print(0)
	else:
		ct = 0
		if x == 0:
			ct += 1
		for i in mods:
			if (x - i) / base_score >= 0 and (x - i) % base_score == 0:
				ct += 1
		print(ct)


t = int(input())
for i in range(t):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	s = input()
	weights = []
	bal = 0
	for i in range(len(s)):
		if s[i] == '0':
			bal = bal + 1
			weights.append(bal)
		else:
			bal = bal - 1
			weights.append(bal)
	if weights[len(s) - 1] == 0:
		if x in weights:
			print(-1)
		else:
			print(0)
	elif weights[len(s) - 1] < 0:
		y = weights[len(s) - 1]
		count = 0
		if x == 0:
			count += 1
		for k in weights:
			if k - x >= 0 and (k - x) % y == 0:
				count += 1
		print(count)
	elif weights[len(s) - 1] > 0:
		y = weights[len(s) - 1]
		count = 0
		if x == 0:
			count += 1
		for k in weights:
			if x - k >= 0 and (x - k) % y == 0:
				count += 1
		print(count)


from collections import Counter
import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	d = Counter()
	cnt = 0
	s = input()
	for i in range(n):
		if s[i] == '0':
			cnt += 1
			d[cnt] += 1
		else:
			cnt -= 1
			d[cnt] += 1
	if cnt == 0:
		if x in d:
			print(-1)
		else:
			print(0)
	else:
		ans = 0
		if x == 0:
			ans = 1
		for (k, v) in d.items():
			if (x - k) % cnt == 0 and (x - k) // cnt >= 0:
				ans += v
		print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	dp = [0]
	for i in s:
		if i == '0':
			dp.append(1 + dp[-1])
		else:
			dp.append(dp[-1] - 1)
	m = dp[-1]
	if m == 0:
		f = 0
		for i in range(1, n + 1):
			if dp[i] == x:
				f = -1
				break
		print(f)
		continue
	c = 0
	for i in range(1, n + 1):
		if (x - dp[i]) / m >= 0 and (x - dp[i]) % m == 0:
			c = c + 1
	if x == 0:
		print(c + 1)
	else:
		print(c)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(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
import sys
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	s = input()
	(cnt0, cnt1) = (0, 0)
	l1 = [0]
	l2 = []
	for i in range(n):
		if s[i] == '1':
			cnt1 += 1
		else:
			cnt0 += 1
		l1.append(cnt0 - cnt1)
		l2.append(cnt1 - cnt0)
	ans = 0
	flag = 0
	for i in range(n):
		try:
			(z, z1) = ((x - l1[i]) % (cnt0 - cnt1), (x - l1[i]) // (cnt0 - cnt1))
			if z == 0 and z1 >= 0:
				ans += 1
		except:
			if x == l1[i]:
				flag = 1
				break
	if flag:
		print(-1)
	else:
		print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(str(input()))
	prefx = []
	zeroes = 0
	ones = 0
	for i in range(0, n):
		if s[i] == '0':
			zeroes += 1
		else:
			ones += 1
		prefx.append(zeroes - ones)
	sett = []
	t = 1
	if x == 0 and prefx[-1] == 0:
		print(-1)
	elif prefx[-1] == 0:
		if x == 0:
			sett.append(0)
		for i in prefx:
			if i == x:
				print(-1)
				break
		else:
			print(0)
	else:
		if x == 0:
			sett.append(0)
		for i in prefx:
			val = (x - i) / prefx[-1]
			if val.is_integer() and val >= 0:
				sett.append(val * n + t)
			t += 1
		print(len(sett))


t = int(input())
for rwerwe in range(t):
	(n, x) = map(int, input().split())
	s = input()
	z = s.count('0')
	j = s.count('1')
	roz = z - j
	d = {}
	rozn = 0
	d[0] = 0
	for i in range(n):
		if s[i] == '0':
			rozn += 1
		else:
			rozn -= 1
		d[rozn] = 0
	rozn = 0
	for i in range(n):
		if s[i] == '0':
			rozn += 1
		else:
			rozn -= 1
		d[rozn] += 1
	if roz == 0:
		try:
			wyn = d[x]
			print(-1)
		except Exception:
			print(0)
	else:
		if x > 0:
			if x > 2 * n:
				x -= abs(roz) * ((x - 2 * n) // abs(roz))
		if x < 0:
			if x < -2 * n:
				x += abs(roz) * ((-x - 2 * n) // abs(roz))
		wyn = 0
		i = x
		while abs(i) <= 4 * n:
			try:
				wyn += d[i]
			except Exception:
				xx = 0
			i -= roz
		if x == 0:
			wyn += 1
		print(wyn)


def solve():
	(n, x) = [int(s) for s in input().split(' ')]
	s = input()
	balances = []
	balance = 0
	for ch in s:
		if ch == '0':
			balance += 1
		else:
			balance -= 1
		balances.append(balance)
	ans = 0
	round_balance = balances[-1]
	for balance in balances:
		needed = x - balance
		if needed == 0 and round_balance == 0:
			print('-1')
			return
		if round_balance != 0 and needed * round_balance >= 0 and (needed % round_balance == 0):
			ans += 1
	if x == 0:
		ans += 1
	print(ans)
for _ in range(int(input())):
	solve()


import sys, math
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = str(input())
	ans = 0
	z = 0
	o = 0
	if x < 0:
		tmp = []
		for i in range(n):
			if a[i] == '0':
				tmp.append('1')
			else:
				tmp.append('0')
		del a
		a = []
		for i in range(n):
			a.append(tmp[i])
		x *= -1
	for i in range(n):
		if a[i] == '0':
			z += 1
		else:
			o += 1
		if z - o == x:
			ans += 1
	d = z - o
	c1 = 0
	c2 = 0
	if d == 0:
		if ans > 0:
			print(-1)
		else:
			print(0)
		continue
	if x == 0:
		ans += 1
	z = 0
	o = 0
	for i in range(n):
		if a[i] == '0':
			z += 1
		else:
			o += 1
		if d >= 0:
			var = x - (z - o)
			if var > 0 and var % d == 0:
				ans += 1
		else:
			var = x - (z - o)
			var *= -1
			D = d * -1
			if var > 0 and var % D == 0:
				ans += 1
	print(ans)


t = int(input())
for i2 in range(t):
	(n, x) = map(int, input().split())
	s = str(input())
	(count0, count1, b, min, dp, ans) = (0, 0, 0, 0, [0] * 100001, 0)
	n = len(s)
	for i in range(n):
		if s[i] == '0':
			count0 += 1
		else:
			count1 += 1
		dp[i] = count0 - count1
	if dp[n - 1] == 0:
		if x in dp:
			print(-1)
		else:
			print(0)
		continue
	for i in range(n):
		if (dp[i] - x % dp[n - 1]) % dp[n - 1] == 0 and (x - dp[i]) / dp[n - 1] >= 0:
			ans += 1
	if x == 0:
		ans += 1
	print(ans)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	s = input().rstrip()
	M = len(s)
	T = []
	p = q = 0
	for i in range(M):
		if s[i] == '0':
			p += 1
		else:
			q += 1
		T.append(p - q)
	X = p - q
	cnt = 0
	if x == 0:
		cnt += 1
	if X == 0:
		if x in T:
			print(-1)
		else:
			print(cnt)
	elif X > 0:
		for t in T:
			k = x - t
			if k >= 0 and k % X == 0:
				cnt += 1
		print(cnt)
	else:
		for t in T:
			k = x - t
			if -k >= 0 and -k % -X == 0:
				cnt += 1
		print(cnt)