#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<vector<int> >;
using VS = vector<string>;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair<int, int>;
using VPII = vector<pair<int, int> >;
template <typename T = int>
using VT = vector<T>;
template <typename T = int>
using VVT = vector<vector<T> >;
template <typename T = int>
using LIM = numeric_limits<T>;
template <typename T = int>
using OSI = ostream_iterator<T>;
template <typename T>
inline istream &operator>>(istream &s, vector<T> &v) {
  for (T &t : v) {
    s >> t;
  }
  return s;
}
template <typename T>
inline ostream &operator<<(ostream &s, const vector<T> &v) {
  for (int i = 0; i < int(v.size()); ++i) {
    s << (" " + !i) << v[i];
  }
  return s;
}
void in_impl(){};
template <typename T, typename... TS>
void in_impl(T &head, TS &...tail) {
  cin >> head;
  in_impl(tail...);
}
template <typename T>
inline T fromString(const string &s) {
  T res;
  istringstream iss(s);
  iss >> res;
  return res;
}
template <typename T>
inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
}
template <typename T>
inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
class DisjointSetForest {
 private:
  const int N;
  vector<int> parent;
  vector<int> rank;
  int groups_;
  std::vector<int> sizes;

 public:
  DisjointSetForest(int n)
      : N(n), parent(N), rank(N, 0), groups_(N), sizes(N, 1) {
    std::iota(parent.begin(), parent.end(), 0);
    return;
  }
  int find(int x) {
    if (parent[x] == x) {
      return x;
    }
    return parent[x] = find(parent[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    }
    if (rank[x] < rank[y]) {
      parent[x] = y;
      sizes[y] += sizes[x];
    } else {
      parent[y] = x;
      sizes[x] += sizes[y];
      if (rank[x] == rank[y]) {
        ++rank[x];
      }
    }
    --groups_;
    return true;
  }
  int groups() const { return groups_; }
  int groupSize(const int x) { return sizes[find(x)]; }
};
bool solve() {
  int N, K;
  in_impl(N, K);
  ;
  string S;
  in_impl(S);
  ;
  DisjointSetForest dsf(N + 2);
  for (int i = (int)(0); i < (int)(N); ++i) {
    const int d = S[i] - '0';
    if (S[i] != '?') {
      dsf.unite(i, N + d);
    }
  }
  for (int i = (int)(0); i < (int)(N - K); ++i) {
    dsf.unite(i, i + K);
  }
  for (int i = (int)(0); i < (int)(N - K); ++i) {
    if (dsf.same(N, N + 1)) {
      return false;
    }
  }
  for (int i = (int)(0); i < (int)(N); ++i) {
    if (S[i] == '?') {
      if (dsf.same(i, N)) {
        S[i] = '0';
      } else if (dsf.same(i, N + 1)) {
        S[i] = '1';
      }
    }
  }
  int zeros = 0, ones = 0;
  for (int i = (int)(0); i < (int)(K); ++i) {
    zeros += S[i] == '0';
    ones += S[i] == '1';
  }
  if (K / 2 < zeros || K / 2 < ones) {
    return false;
  }
  for (int i = (int)(K); i < (int)(N); ++i) {
    zeros -= S[i - K] == '0';
    zeros += S[i] == '0';
    ones -= S[i - K] == '1';
    ones += S[i] == '1';
    if (K / 2 < zeros || K / 2 < ones) {
      return false;
    }
  }
  return true;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(12) << fixed;
  int T;
  in_impl(T);
  ;
  for (int REP_COUNTER_196 = (int)(0); REP_COUNTER_196 < (int)(T);
       ++REP_COUNTER_196) {
    cout << (solve() ? "YES" : "NO") << '\n';
  }
  cout << flush;
  return 0;
}
