#include <bits/stdc++.h>
const long long int mod = 1000000007;
const long long int AM = 2e5 + 5;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    char s[n + 1];
    for (__typeof(0) i = 0; i < n; ++i) cin >> s[i];
    long long int flag = 1;
    char b[k + 1];
    for (__typeof(0) i = 0; i < k; ++i) b[i] = '2';
    for (__typeof(0) i = 0; i < n; ++i) {
      if (i < k) {
        if (s[i] != '?') b[i] = s[i];
      } else {
        if (s[i] != '?' && b[i % k] != '2' && b[i % k] != s[i])
          flag = 0;
        else {
          if (s[i] != '?') {
            b[i % k] = s[i];
          }
        }
      }
    }
    long long int z = 0, o = 0;
    for (__typeof(0) i = 0; i < k; ++i) {
      if (b[i] == '0')
        z++;
      else if (b[i] == '1')
        o++;
    }
    if (z <= k / 2 && o <= k / 2 && flag == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
