#include <bits/stdc++.h>
using namespace std;
long long cnt = 0;
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool sortByVal(const pair<pair<long long, long long>, long long> &a,
               const pair<pair<long long, long long>, long long> &b) {
  return a.second > b.second;
}
long long Powb(long long b, long long n) {
  if (n == 0) return 1LL;
  if (n == 1) return b;
  long long temp = Powb(b, n / 2);
  if (n % 2 == 0) {
    return (temp * temp) % 1000000007LL;
  } else {
    return (b * ((temp * temp) % 1000000007LL)) % 1000000007LL;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    long long i, j, m, n, k, sum = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0,
                             maxi = 0;
    cin >> n >> k;
    string a;
    cin >> a;
    vector<long long> b(k, 1000000007LL);
    for (i = 0; i < n; i += k) {
      d = 0;
      for (j = i; j < i + k && j < n; j++) {
        c = a[j] - '0';
        if (a[j] != '?') {
          if (b[d] == 1000000007LL && (c == 0 || c == 1))
            b[d] = c;
          else {
            if (c == 0 || c == 1) {
              if (b[d] != 1000000007LL) {
                if (b[d] != c) {
                  f = 1000000007LL;
                  break;
                }
              }
            }
          }
        }
        d++;
      }
    }
    if (f == 1000000007LL)
      cout << "NO"
           << "\n";
    else {
      c = 0;
      d = 0;
      for (i = 0; i < k; i++) {
        if (b[i] == 1)
          d++;
        else if (b[i] == 0)
          c++;
      }
      e = k / 2;
      if (c > e || d > e)
        cout << "NO"
             << "\n";
      else {
        cout << "YES"
             << "\n";
      }
    }
  }
}
