#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T, typename TT>
inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {
  return os << t.first << " " << t.second;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &t) {
  for (T i : t) os << i << " ";
  return os;
}
template <typename T>
inline ostream &operator<<(ostream &os, const set<T> &t) {
  for (T &i : t) os << i << " ";
  return os;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &os, const map<T1, T2> &t) {
  for (auto &i : t) os << i.first << " : " << i.second << '\n';
  return os;
}
template <typename T>
inline istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
  for (pair<T1, T2> &t : v) is >> t.first >> t.second;
  return is;
}
const long long mod = 1e9 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long o = 0, z = 0, q = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == '1')
      o++;
    else if (s[i] == '0')
      z++;
  }
  if (o > k / 2 or z > k / 2 or (k % 2 == 1)) {
    cout << "NO" << '\n';
    return;
  }
  o = k / 2 - o, z = k / 2 - z;
  vector<long long> cnt = {z, o};
  for (int i = k; i < n; i++) {
    if (s[i] == '?') {
      if (s[i - k] != '?') s[i] = s[i - k];
      continue;
    }
    if (s[i - k] != '?' and s[i] != s[i - k]) {
      cout << "NO" << '\n';
      return;
    }
    if (s[i - k] == '?') {
      if (!cnt[s[i] - '0']) {
        cout << "NO" << '\n';
        return;
      }
      cnt[s[i] - '0']--;
    };
  }
  cout << "YES" << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
