#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long mod = 1e9 + 7) {
  long long res = 1;
  long long i = 0;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long modInverse(long long a, long long m = 1e9 + 7) {
  if (a % m == 0) return INT_MIN;
  return power(a, m - 2, m);
}
const long long mod = 1e9 + 7;
int32_t main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  cin >> T;
  long long n, res, ones, zeros, b, k;
  string s;
  while (T--) {
    cin >> n >> k >> s;
    zeros = 0;
    ones = 0;
    for (long long i = 0; i < k; i++) {
      zeros += (s[i] == '0');
      ones += (s[i] == '1');
    }
    if (ones > (k / 2) || zeros > (k / 2)) {
      cout << "NO"
           << "\n";
      continue;
    }
    res = true;
    for (long long i = 0, j; res && (j = i + k) < n; i++) {
      if (s[i] != '?' && s[j] != '?') {
        if (s[i] != s[j]) res = false;
      } else if (s[i] != '?' && s[j] == '?')
        s[j] = s[i];
      else if (s[i] == '?' && s[j] != '?') {
        for (b = i; b >= 0; b -= k) s[b] = s[j];
        if (s[b + k] == '0')
          zeros++;
        else
          ones++;
      }
      if (ones > (k / 2) || zeros > (k / 2)) res = false;
    }
    cout << (res ? "YES" : "NO") << "\n";
  }
  return 0;
}
