#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<char> base(k, '?');
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') {
      if (base[i % k] == '1') {
        continue;
      }
      if (base[i % k] == '0') {
        cout << "NO" << endl;
        return;
      }
      if (base[i % k] == '?') {
        base[i % k] = '1';
      }
    } else if (s[i] == '0') {
      if (base[i % k] == '0') {
        continue;
      }
      if (base[i % k] == '1') {
        cout << "NO" << endl;
        return;
      }
      if (base[i % k] == '?') {
        base[i % k] = '0';
      }
    } else {
    }
  }
  long long zero = 0, one = 0;
  for (long long i = 0; i < k; i++) {
    if (base[i] == '0')
      zero++;
    else if (base[i] == '1')
      one++;
  }
  if (one <= k / 2 && zero <= k / 2)
    cout << "YES" << endl;
  else {
    cout << "NO" << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
