#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    char cur = '?';
    for (int j = i; j < n; j += k) {
      if (s[j] != '?') {
        cur = s[j];
        break;
      }
    }
    for (int j = i; j < n; j += k) {
      if (s[j] != '?' && s[j] != cur) {
        cout << "NO\n";
        return;
      }
      s[j] = cur;
    }
  }
  long long c[2] = {0, 0};
  for (int i = 0; i < k; i++) {
    if (s[i] == '?') continue;
    c[s[i] - '0']++;
  }
  if (c[0] > k / 2 || c[1] > k / 2) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  return;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }
  return 0;
}
