#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, cnt = 0, flag = 1;
    string s;
    cin >> n >> k >> s;
    for (int i = 0; i < k; i++) {
      if (s[i] == '1') {
        cnt++;
      } else if (s[i] == '?') {
        for (int j = 1; i + j * k < n; j++) {
          if (s[i + j * k] != '?') {
            s[i] = s[i + j * k];
            cnt += s[i] - '0';
            break;
          }
        }
      }
    }
    for (int i = 0; i < k; i++) {
      if (s[i] == '?') {
        if (cnt < k / 2) {
          s[i] = '1';
          cnt++;
        } else {
          s[i] = '0';
        }
      }
    }
    for (int i = k; i < n; i++) {
      if (s[i] == '?') {
        s[i] = s[i - k];
      } else if (s[i] != s[i - k]) {
        flag = 0;
        break;
      }
    }
    if (flag == 0 || cnt != k / 2) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
}
