#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
void solve() {
  int n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;
  for (int r = 0; r < k; r++) {
    std::map<char, int> count;
    for (int i = r; i < n; i += k) {
      count[s[i]]++;
    }
    if (count['0'] > 0 && count['1'] > 0) {
      std::cout << "NO" << std::endl;
      return;
    }
    for (int i = r; i < n; i += k) {
      if (count['0'] > 0) s[i] = '0';
      if (count['1'] > 0) s[i] = '1';
    }
  }
  std::vector<int> prefix1(s.length() + 1), prefixA(s.length() + 1);
  for (int i = 1; i <= n; i++) {
    prefix1[i] = (s[i - 1] == '1') + prefix1[i - 1];
    prefixA[i] = (s[i - 1] == '?') + prefixA[i - 1];
  }
  for (int i = k; i <= n; i++) {
    int min = prefix1[i] - prefix1[i - k];
    int max = min + prefixA[i] - prefixA[i - k];
    if (min <= k / 2 && k / 2 <= max) {
      continue;
    } else {
      std::cout << "NO" << std::endl;
      return;
    }
  }
  std::cout << "YES" << std::endl;
}
int main() {
  std::ios::sync_with_stdio(false);
  int t;
  std::cin >> t;
  while (t--) solve();
  return 0;
}
