#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test;
  cin >> test;
  while (test--) {
    long long n, k;
    string s;
    cin >> n >> k >> s;
    bool flag = 0;
    for (long long i = 0; i < k; ++i) {
      char c = s[i];
      for (long long j = i + k; j < n; j += k) {
        if (s[j] == '0' and c == '1') {
          flag = 1;
          break;
        } else if (s[j] == '1' and c == '0') {
          flag = 1;
          break;
        } else if (c == '?' and s[j] != '?') {
          c = s[j];
        }
      }
      if (flag) break;
      s[i] = c;
    }
    if (flag) {
      cout << "NO"
           << "\n";
      continue;
    }
    long long cnt0 = 0, cnt1 = 0;
    for (long long i = 0; i < k; ++i) {
      if (s[i] == '1')
        cnt1++;
      else if (s[i] == '0')
        cnt0++;
    }
    if (cnt0 > (k / 2) or cnt1 > (k / 2))
      cout << "NO"
           << "\n";
    else
      cout << "YES"
           << "\n";
  }
}
