#include <bits/stdc++.h>
char st[1000010];
int a[1000010];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, k;
    scanf("%d%d%s", &n, &k, st + 1);
    for (int i = 0; i < k; i++) a[i] = -1;
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      if (st[i] == '?') continue;
      if (a[i % k] == -1)
        a[i % k] = st[i] - '0';
      else if (a[i % k] != st[i] - '0') {
        flag = true;
        break;
      }
    }
    if (flag) {
      puts("NO");
      continue;
    }
    int cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < k; i++) {
      if (a[i] == 0) cnt0++;
      if (a[i] == 1) cnt1++;
    }
    if (cnt0 > k / 2 || cnt1 > k / 2)
      puts("NO");
    else
      puts("YES");
  }
  return 0;
}
