#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  for (long long i = 0; i < k; i++) {
    if (str[i] == '?') {
      for (long long j = k + i; j < n; j += k) {
        if (str[j] != '?') {
          str[i] = str[j];
          break;
        }
      }
    }
  }
  long long z = 0, o = 0, u = 0;
  for (long long i = 0; i < k; i++) {
    if (str[i] == '0') z++;
    if (str[i] == '?') u++;
  }
  o = k - z - u;
  if (z > k / 2 || o > k / 2) {
    cout << "NO" << endl;
    return;
  }
  for (long long i = k; i < n; i++) {
    if (str[i] == str[i % k] || str[i] == '?' || str[i % k] == '?') continue;
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
