#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int ones = 0, zeros = 0;
    for (int i = 0; i < k; i++) {
      ones += s[i] == '1';
      zeros += s[i] == '0';
    }
    bool ok = 1;
    if (ones > k / 2 || zeros > k / 2) ok = 0;
    for (int i = k; i < n; i++) {
      if (s[i] == '?' && s[i - k] != '?') s[i] = s[i - k];
      if (s[i - k] == '0')
        zeros--;
      else if (s[i - k] == '1')
        ones--;
      if (s[i] == '0') zeros++;
      if (s[i] == '1') ones++;
      if (ones > k / 2 || zeros > k / 2) ok = 0;
      if (s[i - k] != '?' && s[i] != '?' && s[i - k] != s[i]) ok = 0;
    }
    if (ok)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
