//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

int sign (int x) {
  if (!x) return 0;
  if (x > 0) return 1;
  return -1;
}

long test () {
  auto s = readln.splitter.map!(to!int);
  immutable n = s.front;
  s.popFront;
  immutable x = s.front;
  auto t = readln[0 .. n];
  auto a = new int[n+1];
  foreach (i; 0 .. n) {
    a[i+1] = a[i] + (t[i] == '1' ? -1 : 1);
  }
  debug stderr.writeln (a);
  immutable m = a.back;
  if (m == 0) {
    return (minElement (a) <= x && x <= maxElement (a)) ? -1 : 0;
  }
  long r = 0;
  foreach (i; 0 .. n) {
    int delta = x - a[i];
    if (m > 0) {
      if (delta >= 0 && !(delta % m)) ++r;
    } else {
      if (delta <= 0 && !((-delta) % (-m))) ++r;
    }
  }
  return r;
}

void main() {
  auto nt = readln.strip.to!int;
  foreach (tid; 0 .. nt) {
    writeln (test ());
  }
}

