#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    bool ans = true;
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    for (int i = k; i < n; i++) {
      if (s[i - k] != '?') {
        if (s[i] == '?') {
          s[i] = s[i - k];
        } else {
          if (s[i - k] != s[i]) {
            ans = false;
            break;
          }
        }
      } else {
        if (s[i] != '?') {
          s[i - k] = s[i];
        }
      }
    }
    if (ans) {
      for (int i = n - k - 1; i >= 0; i--) {
        if (s[i + k] != '?') {
          if (s[i] == '?') {
            s[i] = s[i + k];
          } else {
            if (s[i + k] != s[i]) {
              ans = false;
              break;
            }
          }
        } else {
          if (s[i] != '?') {
            s[i + k] = s[i];
          }
        }
      }
      int one = 0, zero = 0;
      for (int i = 0; i < k; i++) {
        if (s[i] == '1')
          one++;
        else if (s[i] == '0')
          zero++;
      }
      int q = k - one - zero;
      if (min(one, zero) + q < max(one, zero)) {
        ans = false;
      }
    }
    if (ans)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
