#include <bits/stdc++.h>
using namespace std;
int n, k;
void solve() {
  cin >> n >> k;
  int zero = 0, one = 0;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    if (s[i] == '?') {
      for (int j = i + k; j < n; j += k) {
        if (s[j] != '?') {
          s[i] = s[j];
          break;
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    if (s[i] != '?') {
      for (int j = i + k; j < n; j += k) {
        if (s[j] == '?')
          s[j] = s[i];
        else if (s[j] != s[i]) {
          cout << "NO\n";
          return;
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    if (s[i] == '1')
      one++;
    else if (s[i] == '0')
      zero++;
  }
  if (zero <= k / 2 && one <= k / 2)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
