#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int i, j, d, k, z = 0, o = 0, x, y, n, t, sum = 0;
  string s;
  cin >> n >> k >> s;
  vector<int> vis(n, 0);
  for (i = 0; i < n; i++) {
    if (vis[i]) continue;
    char ch = '?';
    j = i;
    while (j < n && s[j] == '?') {
      vis[j] = 1;
      j += k;
    }
    if (j < n) ch = s[j];
    if (ch == '?') continue;
    for (j = i; j < n; j = j + k) {
      vis[j] = 1;
      if (s[j] == '?') {
        s[j] = ch;
      } else if (s[j] != ch) {
        cout << "NO";
        return;
      }
    }
  }
  o = 0;
  z = 0;
  for (i = 0; i < k; i++) {
    if (s[i] == '1')
      o++;
    else if (s[i] == '0')
      z++;
  }
  if (o > k / 2 || z > k / 2) {
    cout << "NO";
    return;
  }
  for (i = k; i < n; i++) {
    if (s[i - k] == '1')
      o--;
    else if (s[i - k] == '0')
      z--;
    if (s[i] == '1')
      o++;
    else if (s[i] == '0')
      z++;
    if (o > k / 2 || z > k / 2) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
