#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long int zer = 0, one = 0;
    bool chk = true;
    for (long long int i = 0; i < k; i++) {
      long long int tmp = -1;
      for (long long int j = i; j < n; j += k) {
        if (s[j] != '?') {
          if (tmp != -1 && s[j] - '0' != tmp) {
            chk = false;
            break;
          }
          tmp = s[j] - '0';
        }
      }
      if (tmp != -1) {
        (tmp == 0 ? zer : one)++;
      }
    }
    if (max(zer, one) > k / 2) {
      chk = false;
    }
    cout << (chk ? "YES\n" : "NO\n");
  }
}
