#include <bits/stdc++.h>
using namespace std;
int INF = INT_MAX;
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  bool ok = true;
  for (int i = 0; i < n - k; i++) {
    if (s[i] == '?' && s[i + k] != '?') {
      s[i] = s[i + k];
    } else if (s[i] != '?' && s[i + k] == '?') {
      s[i + k] = s[i];
    } else if (s[i] != s[i + k])
      ok = false;
  }
  vector<int> pref0(n);
  vector<int> pref1(n);
  if (s[0] == '0') {
    pref0[0] = 1;
  } else if (s[0] == '1') {
    pref1[0] = 1;
  }
  for (int i = 1; i < n; i++) {
    pref0[i] = pref0[i - 1];
    pref1[i] = pref1[i - 1];
    if (s[i] == '0') {
      pref0[i]++;
    } else if (s[i] == '1') {
      pref1[i]++;
    }
  }
  for (int i = 0; i < n - k + 1; i++) {
    if (pref0[i + k - 1] - (i >= 1 ? pref0[i - 1] : 0) > k / 2) ok = false;
    if (pref1[i + k - 1] - (i >= 1 ? pref1[i - 1] : 0) > k / 2) ok = false;
  }
  if (ok) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) solve();
}
