#include <bits/stdc++.h>
char s[300005];
char keep[300005];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, k;
    scanf("%d%d%s", &n, &k, s + 1);
    int ok = 1;
    for (int i = 1; i <= k; i++) {
      int p = i, size = 0;
      while (p <= n) {
        keep[++size] = s[p];
        p += k;
      }
      int find0 = 0, find1 = 0;
      for (int j = 1; j <= size; j++) {
        if (keep[j] == '0') find0 = 1;
        if (keep[j] == '1') find1 = 1;
      }
      if (find0 && find1)
        ok = 0;
      else if (find0)
        s[i] = '0';
      else if (find1)
        s[i] = '1';
      else {
      }
    }
    if (!ok)
      printf("NO\n");
    else {
      int cnt0 = 0, cnt1 = 0, cntx = 0;
      for (int i = 1; i <= k; i++) {
        if (s[i] == '0')
          cnt0++;
        else if (s[i] == '1')
          cnt1++;
        else
          cntx++;
      }
      if (cnt0 == cnt1) {
        if (cntx % 2) ok = 0;
      } else {
        int diff = cnt0 - cnt1;
        if (diff < 0) diff *= -1;
        if (diff > cntx)
          ok = 0;
        else {
          if (diff % 2 != cntx % 2) ok = 0;
        }
      }
      if (ok)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
