#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    queue<char> qu;
    bool no = 0;
    ll l = 0, r = k - 1, df = 0;
    ll z = 0, o = 0, del = 0, q = 0, X = 0;
    for (int i = 0; i < k; i++) {
      set<char> st;
      for (int j = i; j < n; j += k) {
        if (s[j] != '?') st.insert(s[j]);
      }
      if (st.size() > 1) no = 1;
      if (st.size() && *st.begin() == '0')
        z++;
      else if (st.size())
        o++;
    }
    if (max(z, o) > k / 2) no = 1;
    cout << (no ? "NO\n" : "YES\n");
  }
  return 0;
}
