#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const char nl = '\n';
auto clk = clock();
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
void read(long long arr[], long long n) {
  for (long long i = 0; i < n; i++) cin >> arr[i];
}
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  std::map<char, long long int> mp;
  bool consta = true;
  for (long long int i = 0; i < n; i++) {
    mp[s[i]]++;
    if (i > k - 1) {
      if (s[i] == s[i - k]) continue;
      if (s[i] == '?') {
        s[i] = s[i - k];
      } else if (s[i - k] == '?') {
        s[i - k] = s[i];
      } else
        consta = false;
    }
  }
  mp.clear();
  for (long long int i = 0; i < k - 1; i++) {
    mp[s[i]]++;
  }
  for (long long int i = k - 1; i <= n - 1; i++) {
    if (i != k - 1) mp[s[i - k]]--;
    mp[s[i]]++;
    if (mp['1'] > k / 2 || mp['0'] > k / 2) consta = false;
    long long val = (abs(mp['1'] - mp['0']));
    mp['?'] -= val;
    if (mp['?'] < 0 || mp['?'] % 2 != 0) consta = false;
    if (mp['1'] > k / 2 || mp['0'] > k / 2) consta = false;
    mp['?'] += val;
  }
  cout << (consta ? "YES" : "NO") << nl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
