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