#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k, k1, k2, t, n, x, a, b, c, d;
  cin >> t;
  string s;
  while (t--) {
    cin >> n >> k >> s;
    long int mass[k];
    for (long int i = 0; i < k; i++) mass[i] = -1;
    a = 1;
    for (long int i = 0; i < n; i++) {
      if (s[i] != '?' and mass[i % k] != -1 and mass[i % k] != int(s[i])) {
        cout << "NO"
             << "\n";
        a = 0;
        break;
      } else if (s[i] != '?') {
        mass[i % k] = int(s[i]);
      }
    }
    for (long int i = 0; i < n; i++) {
      if (mass[i % k] != -1) s[i] = char(mass[i % k]);
    }
    k1 = 0;
    k2 = 0;
    for (long int i = 0; i < k; i++) {
      if (s[i] == '0')
        k1++;
      else if (s[i] == '1')
        k2++;
    }
    if (a and (k1 > k / 2 or k2 > k / 2)) {
      cout << "NO\n";
      a = 0;
    }
    if (a) cout << "YES\n";
  }
  return 0;
}
