#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long int n, i, j, k, l, sum = 0, g = 0, sum1 = 0, q, one, zero, k1;
    cin >> n >> k1;
    string s;
    cin >> s;
    for (i = 0; i < k1; i++) {
      k = i;
      q = 0;
      zero = 0, one = 0;
      while (k <= n - 1) {
        if (s[k] == '?')
          q++;
        else if (s[k] == '1')
          one++;
        else
          zero++;
        k += k1;
      }
      if (one != 0 && zero != 0) {
        g = 1;
        break;
      } else if (zero != 0) {
        k = i;
        while (k <= n - 1) {
          s[k] = '0';
          k += k1;
        }
      } else if (one != 0) {
        k = i;
        while (k <= n - 1) {
          s[k] = '1';
          k += k1;
        }
      }
    }
    for (i = 0; i < k1; i++) {
      if (s[i] == '1')
        sum++;
      else if (s[i] == '?')
        sum1++;
    }
    if (sum > k1 / 2)
      g = 1;
    else if (sum < (k1 / 2) && sum1 < ((k1 / 2) - sum))
      g = 1;
    if (g == 1)
      cout << "NO"
           << "\n";
    else
      cout << "YES"
           << "\n";
  }
  return 0;
}
