#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long int)1e18 + 19;
const long long int mod = (long long int)1e9 + 7;
long long int ncr(long long int n, long long int r) {
  long long int val = 1, i, j, p = 2;
  for (long long int i = n + 1 - 1; i >= n - r + 1; i--) {
    val *= i;
    while (val % p == 0 && p <= r) {
      val /= p;
      p += 1;
    }
  }
  if (p < r) {
    for (long long int i = p; i < r + 1; i++) val /= i;
  }
  return val;
}
void cazz() {
  long long int t = 1, i = 0, j, n;
  cin >> t;
  while (t--) {
    string s;
    long long int k;
    cin >> n >> k >> s;
    bool f = 0;
    long long int cnt0 = 0, cnt1 = 0;
    for (long long int i = 0; i < k; i++) {
      long long int a = 0, b = 0;
      for (j = i; j < n; j += k) {
        if (s[j] == '?') continue;
        if (s[j] == '0')
          a += 1;
        else
          b += 1;
      }
      if (a && b) {
        f = 1;
        break;
      }
      if (a)
        cnt0 += 1;
      else if (b)
        cnt1 += 1;
    }
    if ((k / 2) < cnt0 || (k / 2) < cnt1) f = 1;
    if (f)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cazz();
  return 0;
}
