#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MAXN = (int)3e5 + 5;
long long n;
void solve() {
  string s;
  int k;
  cin >> n >> k >> s;
  int dg = 0;
  int sor = 0;
  vector<char> ky(k, 'z');
  for (int i = 0; i < n; i++) {
    if (s[i] == '?') continue;
    if (ky[i % k] == 'z') {
      if (s[i] == '?')
        continue;
      else
        ky[i % k] = s[i];
    } else if (ky[i % k] != s[i]) {
      cout << "NO" << '\n';
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ky[i % k] == 'z') continue;
    s[i] = ky[i % k];
  }
  for (int i = 0; i < k; i++) {
    if (s[i] == '0')
      dg--;
    else if (s[i] == '1')
      dg++;
    else
      sor++;
  }
  cout << (sor < abs(dg) ? "NO" : "YES") << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
}
