#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, k, flag = 0;
    cin >> n >> k;
    string s;
    cin >> s;
    for (int i = 0; i < n - k; i++) {
      if (s[i + k] != s[i]) {
        if (s[i + k] == '?' && s[i] != '?')
          s[i + k] = s[i];
        else if (s[i + k] != '?' && s[i] == '?')
          s[i] = s[i + k];
        else
          flag++;
      }
    }
    for (int i = n - 1 - k; i >= 0; i--) {
      if (s[i + k] == '?' && s[i] != '?')
        s[i + k] = s[i];
      else if (s[i + k] != '?' && s[i] == '?')
        s[i] = s[i + k];
    }
    int count1 = 0, count0 = 0, count = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == '1') count1++;
      if (s[i] == '0') count0++;
      if (s[i] == '?') count++;
    }
    if (abs(count1 - count0) > count) flag++;
    for (int i = 0; i < n - k; i++) {
      if (s[i + k] != s[i]) {
        flag++;
      }
    }
    if (flag > 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
