#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  string A;
  cin >> A;
  int zeros = 0, ones = 0;
  bool flag = true;
  for (int i = 0; i < k; i++) {
    int tmp = -1;
    for (int j = i; j < n; j += k) {
      if (A[j] != '?') {
        if (tmp != -1 && A[j] - '0' != tmp) {
          flag = false;
          break;
        }
        tmp = A[j] - '0';
      }
    }
    if (tmp != -1) {
      if (tmp == 0)
        zeros++;
      else
        ones++;
    }
  }
  if (max(zeros, ones) > k / 2) {
    flag = false;
  }
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase;
  cin >> testcase;
  while (testcase--) {
    solve();
  }
  return 0;
}
