#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(1337);
const long long int INF = (long long int)1e18;
const long long int MOD = 1000 * 1000 * 1000 + 7, MOD2 = 274876858367;
const long long int maxn = (long long int)1e5 + 10, L = 22;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool ok = 1;
    long long int a = 0, b = 0;
    for (long long int i = 0; i < k; ++i) {
      if (s[i] == '0')
        ++a;
      else if (s[i] == '1')
        ++b;
    }
    ok = (a <= k / 2 && b <= k / 2);
    for (long long int i = k; ok && i < n; ++i) {
      if (s[i - k] == '?' || s[i] == '?' || s[i - k] == s[i]) {
        if (s[i] == '?') s[i] = s[i - k];
        if (s[i - k] == '?') s[i - k] = s[i];
        continue;
      }
      ok = 0;
    }
    a = b = 0;
    for (long long int i = 0; i < k; ++i) {
      if (s[i] == '0')
        ++a;
      else if (s[i] == '1')
        ++b;
    }
    for (long long int i = k; ok && i < n; ++i) {
      if (s[i - k] == '0')
        --a;
      else if (s[i - k] == '1')
        --b;
      if (s[i] == '0')
        ++a;
      else if (s[i] == '1')
        ++b;
      ok &= (a <= k / 2 && b <= k / 2);
    }
    cout << (ok ? "YES\n" : "NO\n");
  }
  return 0;
}
