#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000;
long long t, n, k, kol[5];
string s;
bool f;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (long long o = 1; o <= t; ++o) {
    cin >> n >> k;
    cin >> s;
    kol[0] = kol[1] = 0;
    for (long long i = 0; i < k; ++i)
      if (s[i] != '?') ++kol[s[i] - '0'];
    f = true;
    if (kol[0] > k / 2 || kol[1] > k / 2) {
      cout << "NO\n";
      continue;
    }
    if (kol[0] == k / 2) {
      for (long long i = 0; i < k; ++i)
        if (s[i] == '?') s[i] = '1';
    } else if (kol[1] == k / 2) {
      for (long long i = 0; i < k; ++i)
        if (s[i] == '?') s[i] = '0';
    }
    for (long long i = k; i < n; ++i) {
      if (s[i - k] != '?') --kol[s[i - k] - '0'];
      if (s[i] != '?') ++kol[s[i] - '0'];
      if (s[i - k] == '1' && s[i] == '?') {
        ++kol[1];
        s[i] = '1';
      }
      if (s[i - k] == '0' && s[i] == '?') {
        ++kol[0];
        s[i] = '0';
      }
      if (kol[0] > k / 2 || kol[1] > k / 2 ||
          (s[i - k] == '0' && s[i] == '1') ||
          (s[i - k] == '1' && s[i] == '0')) {
        f = false;
        break;
      }
    }
    if (f)
      cout << "YES";
    else
      cout << "NO";
    cout << '\n';
  }
  return 0;
}
