#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  for (long long h = 0; h < t; ++h) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool flag = true;
    vector<long long> a(k, -1);
    for (long long i = 0; i < n; ++i) {
      if (s[i] == '1') {
        if (a[i % k] == 0)
          flag = false;
        else
          a[i % k] = 1;
      } else if (s[i] == '0') {
        if (a[i % k] == 1)
          flag = false;
        else
          a[i % k] = 0;
      }
    }
    for (long long i = 0; i < n; ++i) {
      if (s[i] == '?') {
        if (a[i % k] == 0)
          s[i] = '0';
        else if (a[i % k] == 1)
          s[i] = '1';
      }
    }
    long long cnt0 = 0, cnt1 = 0;
    for (long long i = 0; i < k; ++i) {
      if (s[i] == '0')
        ++cnt0;
      else if (s[i] == '1')
        ++cnt1;
    }
    if (abs(cnt0 - cnt1) > k - cnt0 - cnt1) flag = false;
    for (long long i = k; i < n; ++i) {
      if (s[i - k] == '1')
        --cnt1;
      else if (s[i - k] == '0')
        --cnt0;
      if (s[i] == '1')
        ++cnt1;
      else if (s[i] == '0')
        ++cnt0;
      if (abs(cnt0 - cnt1) > k - cnt0 - cnt1) flag = false;
    }
    if (flag) {
      cout << "YES"
           << "\n";
    } else {
      cout << "NO"
           << "\n";
    }
  }
}
