#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, k, i, zero, one, p, z, o;
  string s;
  cin >> t;
  while (t--) {
    cin >> n >> k >> s;
    bool flag = true;
    p = k / 2;
    for (i = k; i < s.size(); i++) {
      if (s[i] != s[i % k]) {
        if (s[i] == '?') {
          s[i] = s[i % k];
        } else if (s[i % k] == '?') {
          s[i % k] = s[i];
        } else {
          flag = false;
          break;
        }
      }
    }
    zero = one = 0;
    for (i = 0; i < k; i++) {
      if (s[i] == '0') {
        zero++;
      } else if (s[i] == '1') {
        one++;
      }
    }
    if (one > p || zero > p) {
      flag = false;
    }
    if (flag == true) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
