#include <bits/stdc++.h>
using namespace std;
char s[1200000];
int a[1200000];
int n, k;
int ABS(int x) {
  if (x > 0) return x;
  return -x;
}
int solve() {
  for (int i = 0; i < k; i++) a[i] = 0;
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '?') continue;
    if (a[i % k] == 0) {
      if (s[i] == '1') a[i % k] = 1;
      if (s[i] == '0') a[i % k] = -1;
    } else {
      if (s[i] == '1' && a[i % k] == -1) return 0;
      if (s[i] == '0' && a[i % k] == 1) return 0;
    }
  }
  int ans = 0, bns = 0;
  for (int i = 0; i < k; i++) ans += a[i], bns += a[i] == 0;
  if (bns >= ABS(ans)) return 1;
  return 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    if (solve())
      printf("YES\n");
    else
      printf("NO\n");
  }
}
