#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool ans = true;
    for (long long i = 0; i < k; i++) {
      char temp = s[i];
      for (long long j = i; j < n; j += k) {
        if (temp == '?' && s[j] != temp) {
          temp = s[j];
          s[i] = temp;
        }
        if (temp != s[j] && s[j] != '?') {
          ans = false;
        }
      }
    }
    long long cnt1 = 0, cnt0 = 0, cnt = 0;
    for (long long i = 0; i < k; i++) {
      if (s[i] == '1') {
        cnt1++;
      } else if (s[i] == '0') {
        cnt0++;
      } else {
        cnt++;
      }
    }
    long long x = cnt - abs(cnt0 - cnt1);
    if (x < 0 || x % 2 == 1) {
      ans = false;
    }
    if (ans) {
      cout << "YES"
           << "\n";
    } else {
      cout << "NO"
           << "\n";
    }
  }
}
