#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  int n, k;
  string s;
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cin >> s;
    int value = 1;
    for (int i = 0; i < n; ++i)
      if (s[i] != s[i % k]) {
        if (s[i % k] == '?')
          s[i % k] = s[i];
        else if (s[i] != '?') {
          value = 0;
          break;
        }
      }
    int c0 = 0, c1 = 0;
    for (int i = 0; i < k; ++i) {
      c0 += s[i] == '0';
      c1 += s[i] == '1';
    }
    if (!value || c0 > k / 2 || c1 > k / 2)
      puts("NO");
    else
      puts("YES");
  }
}
