#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool s() {
  int n, k, i, j;
  char B;
  string a;
  cin >> n >> k >> a;
  unordered_map<char, int> q;
  a.insert(a.begin(), 0);
  for (i = 1; i <= k; i++) {
    B = a[i];
    for (j = i + k; j <= n; j += k) {
      if (B == '?') B = a[i] = a[j];
      if (B != '?' && a[j] != B && a[j] != '?') return 0;
    }
  }
  for (i = 1; i <= k; i++) q[a[i]]++;
  if (max(q['1'], q['0']) > k / 2) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) cout << (s() == 0 ? "NO" : "YES") << '\n';
  return 0;
}
