#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string d;
    cin >> d;
    int flag = 0;
    for (int i = k; i < n; i++) {
      if (d[i] == '?' || d[i] == d[i % k]) {
        continue;
      }
      if (d[i % k] == '?') {
        d[i % k] = d[i];
      } else {
        flag = 1;
        break;
      }
    }
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < k; i++) {
      if (d[i] == '0') {
        sum1++;
      }
      if (d[i] == '1') {
        sum2++;
      }
    }
    if (sum1 > k / 2 || sum2 > k / 2) {
      flag = 1;
    }
    if (flag == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
