#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    string s;
    scanf("%d %d", &n, &k);
    cin >> s;
    bool flg = true;
    for (int i = 0; i < k; ++i) {
      int A[2] = {0};
      int j = 0;
      while (j * k + i <= n - 1) {
        if (s[j * k + i] == '0')
          A[0] = 1;
        else if (s[j * k + i] == '1')
          A[1] = 1;
        j++;
      }
      if (A[0] == 1 && A[1] == 1) {
        flg = false;
        break;
      } else if (A[0] == 1 && A[1] == 0) {
        int t = 0;
        while (t * k + i <= n - 1) {
          s[t * k + i] = '0';
          t++;
        }
      } else if (A[0] == 0 && A[1] == 1) {
        int t = 0;
        while (t * k + i <= n - 1) {
          s[t * k + i] = '1';
          t++;
        }
      }
    }
    if (flg == false)
      printf("NO");
    else {
      int a = 0, b = 0;
      for (int i = 0; i < k; ++i) {
        if (s[i] == '0')
          a++;
        else if (s[i] == '1')
          b++;
      }
      if (max(a, b) > k / 2)
        printf("NO");
      else
        printf("YES");
    }
    printf("\n");
  }
}
