#include <bits/stdc++.h>
using namespace std;
const long long MXN = 2e5 + 10;
long long q, n, k;
long long bit[MXN];
string s;
void solve() {
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) bit[i] = 0;
  for (int i = 0; i < n; i++) {
    long long now = i % k;
    if (s[i] == '?') continue;
    if (bit[now] == 0) {
      bit[now] = (s[i] == '1' ? 1 : 2);
    } else {
      if (bit[now] != (s[i] == '1' ? 1 : 2)) {
        cout << "NO\n";
        return;
      }
    }
  }
  long long cnt0 = 0, cnt1 = 0;
  for (int i = 0; i < k; i++) cnt0 += (bit[i] == 1), cnt1 += (bit[i] == 2);
  if (cnt0 > k / 2 || cnt1 > k / 2) {
    cout << "NO\n";
    return;
  }
  cout << "YES" << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) solve();
  return 0;
}
