#include <bits/stdc++.h>
using namespace std;
void sol() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == s[i % k]) continue;
    if (s[i] == '?')
      s[i] = s[i % k];
    else if (s[i % k] == '?')
      s[i % k] = s[i];
    else {
      cout << "NO\n";
      return;
    }
  }
  int num0 = 0, num1 = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == '0') num0++;
    if (s[i] == '1') num1++;
  }
  if (num0 > k / 2 || num1 > k / 2) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) sol();
}
