#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<set<int>> v(k);
    for (int i = 0; i < s.length(); i++) {
      if (s[i] != '?') v[i % k].insert(s[i]);
    }
    int fl = 0;
    for (int i = 0; i < k; i++) {
      if (v[i].size() == 2) {
        cout << "NO\n";
        fl = 1;
        break;
      }
      if (v[i].size() == 1) {
        s[i] = *v[i].begin();
      }
    }
    int cnt = 0;
    int q = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == '1') {
        cnt++;
      } else if (s[i] == '0') {
        cnt--;
      } else {
        q++;
      }
    }
    if (fl) {
      continue;
    }
    cnt = abs(cnt);
    if ((cnt == 0 && q & 1) || (q < cnt) || (q - cnt) & 1) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
  return 0;
}
