#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool f = 1;
    vector<char> c(k);
    for (int i = 0; i < n; i++) {
      if (s[i] == '?') continue;
      if (c[i % k] && c[i % k] != s[i]) {
        f = 0;
        break;
      }
      c[i % k] = s[i];
    }
    if (!f) {
      cout << "NO\n";
      continue;
    }
    int c0 = 0, c1 = 0, cq = 0;
    for (int i = 0; i < k; i++) {
      if (c[i] == '0')
        c0++;
      else if (c[i] == '1')
        c1++;
      else
        cq++;
    }
    if (min(c0, c1) + cq < max(c0, c1))
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
