#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string a;
    cin >> a;
    bool flag = 1;
    for (int i = 0; i < n - k; i++) {
      if (a[i] == a[i + k]) continue;
      if (a[i] == '?' || a[i + k] == '?') {
        if (a[i] == '?')
          a[i] = a[i + k];
        else
          a[i + k] = a[i];
      } else {
        flag = 0;
        break;
      }
    }
    long long int prefix[n + 1];
    long long int ones[n + 1], zeros[n + 1];
    prefix[0] = 0;
    ones[0] = 0;
    zeros[0] = 0;
    for (long long int i = 0; i < n; i++) {
      if (a[i] == '?')
        prefix[i + 1] = prefix[i] + 1;
      else
        prefix[i + 1] = prefix[i];
      if (a[i] == '1')
        ones[i + 1] = ones[i] + 1;
      else
        ones[i + 1] = ones[i];
      if (a[i] == '0')
        zeros[i + 1] = zeros[i] + 1;
      else
        zeros[i + 1] = zeros[i];
    }
    for (int i = k; i <= n; i++) {
      long long int q, w, e;
      q = prefix[i] - prefix[i - k];
      w = ones[i] - ones[i - k];
      e = zeros[i] - zeros[i - k];
      if (abs(w - e) > q || abs(abs(w - e) - q) % 2 == 1) {
        flag = 0;
        break;
      }
    }
    if (!flag)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
