#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
char str[N];
void work() {
  int n, k;
  scanf("%d %d", &n, &k);
  scanf("%s", str);
  int s0 = 0, s1 = 0, s2 = 0;
  for (int i = 0; i < k; i++) {
    int e0 = 0, e1 = 0;
    for (int j = i; j < n; j += k) {
      if (str[j] == '0') {
        e0 = 1;
      }
      if (str[j] == '1') {
        e1 = 1;
      }
    }
    if (e0 && e1) {
      printf("NO\n");
      return;
    }
    if (e0) {
      s0++;
    } else if (e1) {
      s1++;
    } else {
      s2++;
    }
  }
  if (s1 > k / 2 || s0 > k / 2) {
    printf("NO\n");
  } else {
    printf("YES\n");
  }
}
int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    work();
  }
  return 0;
}
