#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
void PA(const T (&a)[N], int n = -1) {
  if (!n) n = N;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << endl;
}
template <typename T, size_t N, size_t M>
void PA(const T (&a)[N][M], int n, int m) {
  for (int i = 0; i < n; i++) PA(a[i], m);
  cout << endl;
}
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
struct cmp {
  bool operator()(const pair<int, int>& a, const pair<int, int>& b) const {
    if (a.first != b.first)
      return a.first > b.first;
    else
      return a.second < b.second;
  }
};
template <typename T>
T power(T x, int y) {
  T r = 1;
  while (y > 0) {
    if (y & 1) r *= x;
    x *= x;
    y /= 2;
  }
  return r;
}
void print_no() { cout << "nO" << endl; }
void print_yes() { cout << "yEs" << endl; }
string s;
int n, k, k2, q, one, zero, need_q_for_zero, need_q_for_one;
bool DFS(int idx, char ch) {
  if (idx >= n) return true;
  if (s[idx] != ch && s[idx] != '?')
    return false;
  else
    return DFS(idx + k, ch);
}
char find_char(int idx) {
  if (idx >= n) return '?';
  if (s[idx] != '?') return s[idx];
  return find_char(idx + k);
}
void solve() {
  one = zero = q = 0;
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) {
    if (s[i] == '?') {
      s[i] = find_char(i + k);
    }
    if (s[i] == '?')
      q++;
    else if (!DFS(i + k, s[i]))
      return print_no();
  }
  for (int i = 0; i < k; i++)
    if (s[i] == '0')
      zero++;
    else if (s[i] == '1')
      one++;
  k2 = k / 2;
  if (one > k2 || zero > k2) return print_no();
  need_q_for_zero = k2 - zero;
  need_q_for_one = k2 - one;
  if (need_q_for_one + need_q_for_zero != q) return print_no();
  return print_yes();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
