#include <bits/stdc++.h>
template <class T>
inline void rd(T &x) {
  char c = getchar(), f = 0;
  x = 0;
  while (!isdigit(c)) f = (c == '-'), c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x = f ? -x : x;
}
const int MAXN = 3e5 + 7;
int n, k;
char s[MAXN];
int c[MAXN];
void solve() {
  rd(n), rd(k);
  for (int i = (0); i <= (n - 1); ++i) c[i] = -1;
  scanf("%s", s);
  for (int i = (0); i <= (n - 1); ++i) {
    if (s[i] == '1') {
      if (!c[i % k]) {
        puts("NO");
        return;
      }
      c[i % k] = 1;
    } else if (s[i] == '0') {
      if (c[i % k] == 1) {
        puts("NO");
        return;
      }
      c[i % k] = 0;
    }
  }
  int sum = 0, cc = 0;
  for (int i = (0); i <= (k - 1); ++i) {
    if (c[i] == -1)
      cc++;
    else
      sum += c[i];
  }
  if (sum > k / 2) {
    puts("NO");
    return;
  }
  if (sum + cc >= k / 2) {
    puts("YES");
    return;
  }
  puts("NO");
}
int main() {
  int T;
  rd(T);
  while (T--) solve();
  return 0;
}
