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