#include <bits/stdc++.h>
using namespace std;
long long ta, n, m, a, b, c, d, x, y, sum = 0, cnt, k, tot = 0, q, w, u, s, e;
const long long N = 200001;
bool visited[1000019 + 10];
vector<long long> v;
map<long long, long long> mp;
map<long long, bool> mb;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> ta;
  for (long long test = 0; test < ta; test++) {
    cin >> n >> k;
    string s;
    cin >> s;
    s = '*' + s;
    long long one[n + 10], zero[n + 10], un[n + 10];
    memset(one, 0, sizeof one);
    memset(zero, 0, sizeof zero);
    memset(un, 0, sizeof un);
    string t;
    bool flag = 0;
    for (long long i = 0; i <= k; i++) t += s[i];
    for (long long i = k + 1; i <= n; i++) {
      if (s[i] == '?') {
        if (t[i - k] == '?')
          t += '?';
        else if (t[(i - k)] == '1')
          t += '1';
        else
          t += '0';
      } else {
        t += s[i];
        if (t[i - k] == '?') t[i - k] = s[i];
      }
    }
    for (long long i = n - k; i >= 0; i--) {
      if (t[i] == '?') {
        if (t[i + k] == '1')
          t[i] = '1';
        else if (t[i + k] == '0')
          t[i] = '0';
      }
    }
    for (long long i = k + 1; i <= n; i++) {
      if (t[i] != t[i - k]) {
        if (t[i] != '?' and t[i - k] != '?') {
          if (t[i] != t[i - k]) flag = 1;
        }
      }
    }
    for (long long i = 1; i <= n; i++) {
      if (t[i] == '1')
        one[i] = one[i - 1] + 1;
      else
        one[i] = one[i - 1];
      if (t[i] == '0')
        zero[i] = zero[i - 1] + 1;
      else
        zero[i] = zero[i - 1];
      if (t[i] == '?')
        un[i] = un[i - 1] + 1;
      else
        un[i] = un[i - 1];
    }
    for (long long i = k; i <= n; i++) {
      long long lf = i - k;
      long long diff = abs((one[i] - one[lf]) - (zero[i] - zero[lf]));
      long long x = un[i] - un[lf];
      x -= diff;
      if (x < 0 or x & 1) {
        flag = 1;
      }
    }
    if (!flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
