#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
long long modPow(long long a, long long b) {
  if (b == 0) return 1LL;
  if (b == 1) return a % M;
  long long res = 1;
  while (b) {
    if (b % 2 == 1) res = mul(res, a);
    a = mul(a, a);
    b = b / 2;
  }
  return res;
}
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    if (s[i] == '?') {
      for (int j = i + k; j < n; j += k) {
        if (s[j] != '?') {
          s[i] = s[j];
          break;
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    if (s[i] != '?') {
      for (int j = i + k; j < n; j += k) {
        if (s[j] == '?')
          s[j] = s[i];
        else if (s[j] != s[i]) {
          cout << "NO"
               << "\n";
          return;
        }
      }
    }
  }
  int one = 0, zero = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == '1') one++;
    if (s[i] == '0') zero++;
  }
  if (one <= (k / 2) && zero <= (k / 2))
    cout << "YES"
         << "\n";
  else {
    cout << "NO"
         << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
