#include <bits/stdc++.h>
using namespace std;
int t, n, k, val[300010];
char s[300010];
void solve() {
  cin >> n >> k;
  cin >> s + 1;
  for (int i = 1; i <= n - k; i++) {
    if (s[i] != '?' && s[i + k] != '?' && s[i] != s[i + k]) {
      cout << "NO" << endl;
      return;
    }
  }
  for (int i = 1; i <= n - k; i++) {
    if (s[i] != '?' && s[i + k] == '?') s[i + k] = s[i];
  }
  for (int i = n; i >= k + 1; i--) {
    if (s[i] != '?' && s[i - k] == '?') s[i - k] = s[i];
  }
  for (int i = 1; i <= n - k; i++) {
    if (s[i] != '?' && s[i + k] != '?' && s[i] != s[i + k]) {
      cout << "NO" << endl;
      return;
    }
  }
  int s1 = 0, s2 = 0;
  for (int i = 1; i <= k; i++) {
    if (s[i] == '0') s1++;
    if (s[i] == '1') s2++;
  }
  if (s1 > k / 2 || s2 > k / 2) {
    cout << "NO" << endl;
  } else
    cout << "YES" << endl;
  return;
}
int main() {
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
