#include <bits/stdc++.h>
using namespace std;
void printvec(vector<int> n) {
  for (int i = 0; i < n.size(); i++) cout << n[i] << " ";
  cout << endl;
}
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve();
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
void solve() {
  string s;
  bool ok = true;
  int n, k;
  cin >> n >> k;
  cin >> s;
  for (int i = k; i < n; i++) {
    char x = s[i % k];
    if (x == s[i])
      continue;
    else if (s[i] == '?' && x != '?')
      s[i] = x;
    else if (x == '?' && s[i] != '?')
      s[i % k] = s[i];
    else if (x == '?' && s[i] == '?')
      continue;
    else
      ok = false;
  }
  int wa = 0, ze = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == '1') wa++;
    if (s[i] == '0') ze++;
  }
  if (ok && (wa <= k / 2 && ze <= k / 2)) {
    cout << "YES\n";
    return;
  }
  cout << "NO\n";
  return;
}
