#include <bits/stdc++.h>
using namespace std;
int T, n, k;
char s[300005];
int c[300005];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    scanf("%s", s);
    for (int i = 0; i < k; i++) {
      c[i] = -1;
    }
    for (int i = 0; i < n; i++) {
      if (s[i] == '0') {
        if (c[i % k] == -1)
          c[i % k] = 0;
        else if (c[i % k] == 1) {
          printf("NO\n");
          break;
        }
      }
      if (s[i] == '1') {
        if (c[i % k] == -1)
          c[i % k] = 1;
        else if (c[i % k] == 0) {
          printf("NO\n");
          break;
        }
      }
      if (i == n - 1) {
        int g0 = 0, g1 = 0;
        for (int j = 0; j < k; j++)
          if (c[j] == 0)
            g0++;
          else if (c[j] == 1)
            g1++;
        if (g0 * 2 > k || g1 * 2 > k)
          printf("NO\n");
        else
          printf("YES\n");
      }
    }
  }
}
