#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <class A, class B>
ostream &operator<<(ostream &out, vector<pair<A, B>> a);
template <class A>
ostream &operator<<(ostream &out, vector<A> a);
template <class A, class B>
ostream &operator<<(ostream &out, pair<A, B> a) {
  out << a.first << " " << a.second;
  return out;
}
template <class A, class B>
ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
  for (pair<A, B> x : a) out << x.first << " " << x.second << '\n';
  return out;
}
template <class A>
ostream &operator<<(ostream &out, vector<A> a) {
  for (A x : a) out << x << ' ';
  return out;
}
template <class A, class B>
istream &operator>>(istream &in, pair<A, B> &a) {
  in >> a.first >> a.second;
  return in;
}
template <class A>
istream &operator>>(istream &in, vector<A> &a) {
  for (A &x : a) in >> x;
  return in;
}
}  // namespace IO
using namespace IO;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (long long st = (0); st < (long long)(k); ++st) {
    long long cur = -1;
    for (long long j = st; j < n; j += k) {
      if (s[j] != '?') {
        if (cur == -1)
          cur = s[j] - '0';
        else if (cur != s[j] - '0') {
          cout << ("NO") << '\n';
          return;
        }
      }
    }
    if (cur != -1)
      for (long long j = st; j < n; j += k) s[j] = cur + '0';
  }
  long long s1 = 0;
  long long s2 = 0;
  for (long long i = (0); i < (long long)(k); ++i) {
    s1 += s[i] == '0';
    s2 += s[i] == '?';
  }
  if (abs(k - s2 - 2 * s1) <= s2)
    cout << ("YES") << '\n';
  else
    cout << ("NO") << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(30);
  long long q = 1;
  cin >> q;
  while (q--) solve();
}
