#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k;
char s[N];
int pre[N][2];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++) {
      if (i + k <= n && s[i + k] == '?') s[i + k] = s[i];
    }
    for (int i = 1; i <= n; i++) {
      if (s[i] == '0') pre[i][0] = pre[i - 1][0] + 1, pre[i][1] = pre[i - 1][1];
      if (s[i] == '1') pre[i][1] = pre[i - 1][1] + 1, pre[i][0] = pre[i - 1][0];
      if (s[i] == '?') pre[i][1] = pre[i - 1][1], pre[i][0] = pre[i - 1][0];
    }
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      int st = i, ed = i + k - 1;
      if (i + k - 1 > n) break;
      if (pre[ed][0] - pre[st - 1][0] > k / 2) flag = 1;
      if (pre[ed][1] - pre[st - 1][1] > k / 2) flag = 1;
    }
    for (int i = n; i >= 1; i--) {
      if (i - k >= 1 && s[i] != '?' && s[i - k] != '?' && s[i - k] != s[i])
        flag = 1;
    }
    if (flag)
      puts("NO");
    else
      puts("YES");
  }
}
