#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long N, K, Z = 1;
    cin >> N >> K;
    string S;
    cin >> S;
    for (long long i = K; i < N; i++) {
      if (S[i] == '?' && S[i - K] != '?') {
        S[i] = S[i - K];
      } else if (S[i] != '?' && S[i - K] == '?') {
        S[i - K] = S[i];
      } else if (S[i] != '?' && S[i - K] == '?') {
        continue;
      } else if (S[i] != S[i - K]) {
        Z = 0;
      }
    }
    for (long long i = N - 1; i >= K; i--) {
      if (S[i] == '?' && S[i - K] != '?') {
        S[i] = S[i - K];
      } else if (S[i] != '?' && S[i - K] == '?') {
        S[i - K] = S[i];
      } else if (S[i] != '?' && S[i - K] == '?') {
        continue;
      } else if (S[i] != S[i - K]) {
        Z = 0;
      }
    }
    if (Z) {
      long long A = 0, B = 0;
      for (long long i = 0; i < K; i++) {
        if (S[i] == '1') {
          A++;
        }
        if (S[i] == '0') {
          B++;
        }
      }
      if (A * 2 > K || B * 2 > K) {
        Z = 0;
      }
    }
    if (Z) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
