#include <bits/stdc++.h>
using namespace std;
const int max_n = 3 * 1e5 + 8;
char s[max_n];
int n, k;
void solve() {
  scanf("%d%d", &n, &k);
  scanf("%s", s);
  if (k % 2) {
    puts("NO");
    return;
  }
  for (int i = 0; i < k; i++) {
    char u = 0;
    for (int j = i; j < n; j += k) {
      if (s[j] != '?') {
        if (!u)
          u = s[j];
        else if (u != s[j]) {
          puts("NO");
          return;
        }
      }
    }
    if (u) {
      for (int j = i; j < n; j += k) s[j] = u;
    }
  }
  int del = 0, qm = 0;
  for (int i = 0; i < k; i++)
    if (s[i] == '1')
      del++;
    else if (s[i] == '0')
      del--;
    else
      qm++;
  if (qm < abs(del)) {
    puts("NO");
    return;
  }
  puts("YES");
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
