#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T t) {
  cout << t << endl;
}
template <typename T, typename... Args>
void print(T t, Args... args) {
  cout << t << " ";
  print(args...);
}
long long n, k;
string s;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> k >> s;
    long long ch = 0;
    for (long long i = 0; i < k; i++) {
      long long prevchar = -1;
      for (long long j = i; j < n; j += k) {
        if (s[j] == '?') continue;
        if (prevchar == -1)
          prevchar = s[j] - '0';
        else {
          if (prevchar != s[j] - '0') {
            ch = 1;
            break;
          }
        }
      }
      if (prevchar != -1) {
        for (long long j = i; j < n; j += k) {
          if (s[j] == '?') s[j] = (char)(prevchar + '0');
        }
      }
      if (ch) break;
    }
    if (ch) {
      cout << "NO" << '\n';
      continue;
    }
    long long one = 0, zero = 0;
    for (long long i = 0; i < k; i++)
      if (s[i] == '1')
        one++;
      else if (s[i] == '0')
        zero++;
    if (one > k / 2 || zero > k / 2) {
      cout << "NO" << '\n';
      continue;
    }
    one = k / 2 - one;
    zero = k / 2 - zero;
    for (long long i = 0; i < k; i++) {
      if (s[i] != '?') continue;
      for (long long j = i; j < n; j += k)
        if (one > 0)
          s[j] = '1';
        else
          s[j] = '0';
      if (one > 0) one--;
    }
    cout << "YES" << '\n';
  }
}
