#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void solve() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  bool ok = true;
  vec<char> C(K, 'a');
  for (int i = 0; i < N; i++) {
    int k = i % K;
    if (S[i] != '?') {
      if (C[k] == 'a')
        C[k] = S[i];
      else
        ok &= C[k] == S[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (C[i % K] != 'a' && S[i] == '?') S[i] = C[i % K];
  }
  int d = 0, cnt = 0;
  for (int i = 0; i < N; i++) {
    if (i < K) {
      if (S[i] != '?')
        d += (S[i] == '0' ? 1 : -1);
      else
        cnt++;
      if (i == K - 1) {
        ok &= abs(d) <= cnt && (cnt - abs(d)) % 2 == 0;
      }
    }
  }
  cout << (ok ? "YES\n" : "NO\n");
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
