#include <bits/stdc++.h>
using namespace std;
void swap(long long &a, long long &b) {
  long long temp = a;
  a = b;
  b = temp;
}
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b = b >> 1;
  }
  return ans % 1000000007;
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  if (a < b) swap(a, b);
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long n, k, zero = 0, one = 0;
    string s;
    cin >> n >> k >> s;
    bool ans = true;
    for (int i = 0; i < k; i++) {
      int initial = -1;
      for (int j = i; j < n; j += k) {
        if (s[j] != '?') {
          if (initial != -1 && initial != s[j] - '0') {
            ans = false;
            break;
          }
          initial = s[j] - '0';
        }
      }
      if (initial != -1) {
        (initial == 0 ? zero : one)++;
      }
    }
    if ((zero > one ? zero : one) > k / 2) ans = false;
    if (ans)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
  return 0;
}
