#include <bits/stdc++.h>
using namespace std;
const int sz = 6e5 + 5;
char s[sz];
void solve() {
  int n, k;
  scanf("%d %d %s", &n, &k, s);
  int a[2] = {};
  for (int i = 0; i < k; i++) {
    int c = 0;
    for (int j = i; j < n; j += k) {
      if (s[j] == '0') c |= 1;
      if (s[j] == '1') c |= 2;
    }
    if (c == 3) {
      puts("NO");
      return;
    }
    if (c) s[i] = c == 1 ? '0' : '1';
    if (s[i] == '?') continue;
    a[s[i] - '0']++;
  }
  k >>= 1;
  if (a[0] > k or a[1] > k)
    puts("NO");
  else
    puts("YES");
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
