#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ot = 0, zt = 0, o = 0, z = 0, f = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == '0') z++;
      if (s[i] == '1') o++;
    }
    if (z > k / 2 || o > k / 2)
      f = 1;
    else {
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') zt++;
        if (s[i] == '1') ot++;
      }
      for (int i = 0; i < min(n - k, k); i++) {
        if (s[i] == '?') {
          int j = i;
          char rr = '?';
          while (j + k < n) {
            if (s[j + k] != '?') {
              rr = s[j + k];
              break;
            }
            j += k;
          }
          if (rr != '?') {
            s[i] = rr;
            s[i + k] = rr;
            if (rr == '1') {
              o++;
              ot += 2;
            } else {
              z++;
              zt += 2;
            }
          }
        } else if (s[i] != '?' && s[i + k] == '?') {
          s[i + k] = s[i];
          if (s[i] == '0') {
            zt++;
          } else
            ot++;
        }
      }
      if (o > k / 2 || z > k / 2) f = 1;
      if (f == 0) {
        for (int i = 0; i < n - k; i++) {
          if (s[i + k] == '?')
            s[i + k] = s[i];
          else if (s[i + k] != s[i]) {
            f = 1;
            break;
          }
        }
      }
    }
    if (f == 1)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
