#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
int n, v[N], nxt[2][N], dp[N];
int main() {
  int t, n, k;
  cin >> t;
  string s;
  while (t) {
    t--;
    cin >> n >> k;
    cin >> s;
    int a[4] = {0};
    for (int i = 0; i < k; i++) {
      if (s[i] == '0') {
        a[0]++;
      } else if (s[i] == '1') {
        a[1]++;
      }
    }
    if (a[0] > k / 2 || a[1] > k / 2) {
      cout << "NO" << endl;
      continue;
    }
    bool ok = true;
    a[2] = (k / 2) - a[0];
    a[3] = (k / 2) - a[1];
    for (int i = k; i < n; i++) {
      if (s[i - k] != s[i]) {
        if (s[i] == '?') {
          if (s[i - k] == '0') {
            s[i] = '0';
          } else {
            s[i] = '1';
          }
        } else if (s[i] == '0') {
          if (s[i - k] == '1') {
            ok = false;
            break;
          } else {
            if (a[2] > 0) {
              a[2]--;
              a[0]++;
            } else {
              ok = false;
              break;
            }
          }
        } else {
          if (s[i - k] == '0') {
            ok = false;
            break;
          } else {
            if (a[3] > 0) {
              a[3]--;
              a[1]++;
            } else {
              ok = false;
              break;
            }
          }
        }
      }
    }
    if (ok) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
