#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int sz = 1 << 15;
char inbuf[sz], outbuf[sz];
char *pinbuf = inbuf + sz;
char *poutbuf = outbuf;
inline char _getchar() {
  if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;
  return *(pinbuf++);
}
inline void _putchar(char x) {
  if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf;
  *(poutbuf++) = x;
}
inline void flush() {
  if (poutbuf != outbuf)
    fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf;
}
}  // namespace IO
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long read1() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 3e5 + 10;
const int mod = 1e9 + 7;
char ch[N];
int main() {
  int T = read();
  while (T--) {
    int n = read();
    int m = read();
    scanf("%s", ch + 1);
    int c0 = 0, c1 = 0;
    bool ok = 1;
    for (int i = 1; i <= m; i++) {
      int u0 = 0, u1 = 0;
      for (int j = i; j <= n; j += m)
        u0 |= (ch[j] == '0'), u1 |= (ch[j] == '1');
      if (u0 && u1) {
        ok = false;
        break;
      }
      if (ch[i] == '?') {
        if (u0)
          ch[i] = '0';
        else if (u1)
          ch[i] = '1';
      }
    }
    for (int i = 1; i <= m; i++) c0 += ch[i] == '0', c1 += ch[i] == '1';
    if (c0 > m / 2 || c1 > m / 2) ok = 0;
    if (!ok)
      puts("NO");
    else
      puts("YES");
  }
  return 0;
}
