#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int i, j, d, k, z = 0, o = 0, x, y, n, t, sum = 0;
  string s;
  cin >> n >> k >> s;
  long long int to = 0, tz = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '1') {
      o++;
    } else if (s[i] == '0') {
      z++;
    }
  }
  if (o == 0 && z == 0) {
    cout << "YES";
    return;
  }
  for (i = 0; i < n; i++) {
    long long int f = i + k;
    long long int b = i - k;
    char ch = '?';
    if (f < n && s[f] != '?') {
      ch = s[f];
    }
    if (b >= 0 && s[b] != '?') {
      if (ch != '?' && ch != s[b]) {
        cout << "NO";
        return;
      } else
        ch = s[b];
    }
    if (s[i] != '?') {
      if (ch != '?' && ch != s[i]) {
        cout << "NO";
        return;
      } else
        ch = s[i];
    }
    if (ch != '?') {
      if (f < n && s[f] == '?') {
        s[f] = ch;
      }
      if (b >= 0 && s[b] == '?') s[b] = ch;
      if (s[i] == '?') s[i] = ch;
    }
  }
  o = 0;
  z = 0;
  for (i = 0; i < k; i++) {
    if (s[i] == '1')
      o++;
    else if (s[i] == '0')
      z++;
  }
  if (o > k / 2 || z > k / 2) {
    cout << "NO";
    return;
  }
  for (i = k; i < n; i++) {
    if (s[i - k] == '1')
      o--;
    else if (s[i - k] == '0')
      z--;
    if (s[i] == '1')
      o++;
    else if (s[i] == '0')
      z++;
    if (o > k / 2 || z > k / 2) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
