#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int x = 0, y = 0, z = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == '0')
        ++x;
      else if (s[i] == '1')
        ++y;
      else
        ++z;
    }
    bool ok = true;
    if (x != y) {
      int u = max(x, y), v = min(x, y);
      if (z < (u - v)) ok = false;
    }
    for (int l = 0, r = k; r < n; r++, l++) {
      if (s[l] == s[r])
        continue;
      else {
        if (s[l] == '?')
          s[l] = s[r];
        else if (s[r] == '?')
          s[r] = s[l];
        else
          ok = false;
      }
    }
    x = y = z = 0;
    for (int i = n - 1; i >= n - k; i--) {
      if (s[i] == '0')
        ++x;
      else if (s[i] == '1')
        ++y;
      else
        ++z;
    }
    if (x != y) {
      int u = max(x, y), v = min(x, y);
      if (z < (u - v)) ok = false;
    }
    if (ok)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  return 0;
}
