#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
char s[MAXN];
int a[MAXN];
int t, n, k;
void input();
void solve();
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input();
  return 0;
}
void input() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> s[i];
    solve();
  }
}
void solve() {
  for (int i = 0; i < k; i++) a[i] = -1;
  for (int i = 0; i < n; i++)
    if (s[i] != '?') {
      if (s[i] - '0' != a[i % k] && a[i % k] >= 0) {
        cout << "NO" << endl;
        return;
      }
      a[i % k] = s[i] - '0';
    }
  int t = 0, tt = 0;
  for (int i = 0; i < k; i++) {
    t += (a[i] == 0);
    tt += (a[i] == 1);
  }
  (max(t, tt) <= k / 2) ? cout << "YES" << endl : cout << "NO" << endl;
}
