#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void solver() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long one = 0;
  long long zero = 0;
  for (long long i = 0; i < k; i++) {
    char trap = 'z';
    for (long long j = i; j < n; j += k) {
      if (s[j] != '?') {
        if (trap != 'z' && s[j] != trap) {
          cout << "NO"
               << "\n";
          return;
          ;
        }
        trap = s[j];
      }
    }
    if (trap != 'z') (trap == '1' ? one++ : zero++);
  }
  if (one > k / 2 || zero > k / 2)
    cout << "NO"
         << "\n";
  else {
    cout << "YES"
         << "\n";
  }
  return;
  ;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long tc;
  cin >> tc;
  while (tc--) {
    solver();
  }
  return 0;
  ;
}
