#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long w = 0, z = 0;
    bool flag = false;
    for (long long i = 0; i < k; i++) {
      char e = '?';
      for (long long j = i; j < n; j += k) {
        if (s[j] != '?') {
          if (e != '?' && e != s[j]) {
            flag = true;
          }
          e = s[j];
        }
      }
      s[i] = e;
      if (s[i] == '?') {
        w++;
      } else {
        if (s[i] == '0') {
          z--;
        } else {
          z++;
        }
      }
    }
    if (!flag && w >= abs(z)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
