#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
const long long int inf = 1e18;
void solve() {
  long long int n, k;
  string a;
  cin >> n >> k >> a;
  long long int one = 0, two = 0, q = 0;
  for (long long int i = k; i < n; i++) {
    if (a[i] == '1') {
      if (a[q] == '0') {
        cout << "NO";
        return;
      }
      a[q] = '1';
      q++;
    } else if (a[i] == '0') {
      if (a[q] == '1') {
        cout << "NO";
        return;
      }
      a[q] = '0';
      q++;
    } else {
      if (a[q] != '?') {
        a[i] = a[q];
      }
      q++;
    }
  }
  reverse(a.begin(), a.end());
  one = count(a.begin(), a.begin() + k, '1');
  two = count(a.begin(), a.begin() + k, '0');
  q = 0;
  for (long long int i = 0; i < k; i++) {
    if (a[i] == '?' and one < k / 2) {
      a[i] = '1';
      one++;
    } else if (a[i] == '?' and two < k / 2) {
      a[i] = '0';
      two++;
    }
  }
  for (long long int i = k; i < n; i++) {
    if (a[i] == '?') {
      a[i] = a[q];
    }
    q++;
  }
  reverse(a.begin(), a.end());
  one = 0, two = 0;
  one = count(a.begin(), a.begin() + k, '1');
  two = count(a.begin(), a.begin() + k, '0');
  if (one != two) {
    cout << "NO";
    return;
  }
  q = 0;
  for (long long int i = k; i < n; i++) {
    if (a[q] == '1')
      one--;
    else
      two--;
    if (a[i] == '1')
      one++;
    else
      two++;
    q++;
    if (one != two) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int q = 1;
  cin >> q;
  while (q--) {
    solve();
    cout << "\n";
    ;
  }
}
