#include <bits/stdc++.h>
using namespace std;
long long n, t, k, cnt1, cnt0, cntq;
string v;
bool check;
int main() {
  cin >> t;
  for (int ti = 0; ti < t; ++ti) {
    cin >> n >> k;
    cin >> v;
    if (k == 1) {
      cout << "YES" << endl;
      continue;
    }
    if (k & 1) {
      cout << "NO" << endl;
      continue;
    }
    check = true;
    cnt1 = cnt0 = 0;
    for (int i = 0; i < k; ++i) {
      if (v[i] == '1') cnt1++;
      if (v[i] == '0') cnt0++;
    }
    cntq = k - cnt1 - cnt0;
    if (abs(cnt1 - cnt0) > cntq) {
      cout << "NO" << endl;
      continue;
    } else {
      if (abs(cnt1 - cnt0) == cntq) {
        char c = cnt1 > cnt0 ? '0' : '1';
        for (int i = 0; i < k; ++i)
          if (v[i] == '?') v[i] = c;
      }
    }
    for (int i = 0; i + k < n; ++i) {
      if (v[i] == '1') cnt1--;
      if (v[i] == '0') cnt0--;
      if (v[i + k] == '1') cnt1++;
      if (v[i + k] == '0') cnt0++;
      cntq = k - cnt1 - cnt0;
      if (abs(cnt1 - cnt0) > cntq) {
        check = false;
        break;
      }
      if (v[i] != v[i + k] && v[i] != '?' && v[i + k] != '?') {
        check = false;
        break;
      } else {
        if (v[i + k] == '?' && v[i] != '?') {
          v[i + k] = v[i];
          if (v[i] == '1')
            cnt1++;
          else
            cnt0++;
        }
      }
    }
    if (check)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
