#include <bits/stdc++.h>
using namespace std;
long long t, n, k;
int a[1000000];
string s;
int main() {
  cin >> t;
  for (int q = 0; q < t; q++) {
    cin >> n >> k;
    cin >> s;
    bool fl = 0;
    int k1 = 0, k0 = 0;
    for (int i = 0; i < k; i++) {
      if (i < k) {
        if (s[i] == '1') {
          k1++;
        }
        if (s[i] == '0') {
          k0++;
        }
      }
    }
    if (k1 <= k / 2 && k0 <= k / 2) {
      k1 = k / 2 - k1;
      k0 = k / 2 - k0;
      for (int i = k; i < n; i++) {
        if (s[i - k] == '?') {
          if (s[i] == '1') {
            k1--;
          }
          if (s[i] == '0') {
            k0--;
          }
          if (k0 < 0 || k1 < 0) {
            cout << "NO" << '\n';
            fl = 1;
            break;
          }
        } else {
          if (s[i] == '?') {
            s[i] = s[i - k];
          } else {
            if (s[i] != s[i - k] && s[i - k] != '?') {
              cout << "NO" << '\n';
              fl = 1;
              break;
            }
          }
        }
      }
      if (!fl) {
        cout << "YES" << '\n';
      }
    } else {
      cout << "NO" << '\n';
    }
  }
}
