#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
long long powMod(long long x, long long y) {
  long long p = 1;
  while (y) {
    if (y % 2) {
      p = (p * x) % ((long long)1e9 + 7);
    }
    y /= 2;
    x = (x * x) % ((long long)1e9 + 7);
  }
  return p;
}
long long CpowMod(long long x, long long y, long long w) {
  long long p = 1;
  while (y) {
    if (y % 2) {
      p = (p * x) % w;
    }
    y /= 2;
    x = (x * x) % w;
  }
  return p;
}
long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }
long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void solve() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long cnt1 = 0;
    long long cnt0 = 0;
    long long cntq = 0;
    for (int i = 0; i <= k - 1; i++) {
      if (s[i] == '0') {
        cnt0++;
      } else if (s[i] == '1') {
        cnt1++;
      } else {
        cntq++;
      }
    }
    long long flag = 1;
    if (cnt1 > cnt0 + cntq) {
      flag = 0;
    }
    if (cnt0 > cnt1 + cntq) {
      flag = 0;
    }
    for (int i = k; i <= n - 1; i++) {
      if (s[i - k] == '?') {
        s[i - k] = s[i];
      } else if (s[i] == '?') {
        s[i] = s[i - k];
      } else if (s[i] != s[i - k]) {
        flag = 0;
        break;
      }
    }
    for (int i = n - k - 1; i >= 0; i--) {
      if (s[i + k] == '?') {
        s[i + k] = s[i];
      } else if (s[i] == '?') {
        s[i] = s[i + k];
      } else if (s[i] != s[i + k]) {
        flag = 0;
        break;
      }
    }
    cnt1 = 0;
    cnt0 = 0;
    cntq = 0;
    for (int i = 0; i <= k - 1; i++) {
      if (s[i] == '0') {
        cnt0++;
      } else if (s[i] == '1') {
        cnt1++;
      } else {
        cntq++;
      }
    }
    if (cnt1 > cnt0 + cntq) {
      flag = 0;
    }
    if (cnt0 > cnt1 + cntq) {
      flag = 0;
    }
    if (flag)
      cout << "YES";
    else
      cout << "NO";
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  solve();
  return 0;
}
