#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
void solve() {
  long long n, i, j, x, t, y, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (i = 0; i < k; i++) {
    set<long long> st;
    char c = '?';
    for (j = i; j < n; j += k) {
      st.insert(s[j]);
      if (s[j] != '?') c = s[j];
    }
    if (st.size() == 3) {
      cout << "NO\n";
      return;
    }
    if (st.size() == 2 && *(st.begin()) == '0' && *(st.rbegin()) == '1') {
      cout << "NO\n";
      return;
    }
    if (c != '?') {
      for (j = i; j < n; j += k) s[j] = c;
    }
  }
  x = y = 0;
  for (i = 0; i < k; i++) {
    if (s[i] == '1')
      x++;
    else if (s[i] == '0')
      x--;
    else
      y++;
  }
  if (abs(x) > y) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, i, j, x, t, y;
  cin >> t;
  while (t--) solve();
}
