#include <bits/stdc++.h>
using namespace std;
long long int prime = 998244353;
long long int modulo = 1e9 + 7;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
void solve() {
  unordered_map<string, int> look_up;
  unordered_map<long long int, int> lp;
  int n, k;
  string s;
  cin >> n >> k >> s;
  s = 'a' + s;
  char pos[k + 1];
  bool ans = true;
  for (int i = 1; i <= k; i++) {
    pos[i] = 'n';
  }
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= n; j += k) {
      if (s[j] == '1') {
        pos[i] = '1';
        break;
      } else if (s[j] == '0') {
        pos[i] = '0';
        break;
      }
    }
  }
  string t = s;
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= n; j += k) {
      if (s[j] != '?' && s[j] != pos[i]) ans = false;
    }
    t[i] = pos[i];
  }
  int tmp = 0, que = 0;
  for (int i = 1; i <= k; i++) {
    if (t[i] == '0')
      tmp++;
    else if (t[i] == '1')
      tmp--;
    else
      que++;
  }
  if (tmp > 0) {
    if (tmp - que <= 0) tmp = 0;
  } else if (tmp < 0) {
    if (tmp + que >= 0) tmp = 0;
  }
  if (tmp != 0 && que != k) ans = false;
  if (ans)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
