#include <bits/stdc++.h>
using namespace std;
bool solve(string& s, int k) {
  int n = (int)s.length();
  vector<int> v(k, -1);
  bool temp = true;
  for (int i = 0; i < k && temp; i++) {
    int myval = -1;
    if (s[i] != '?') myval = (int)(s[i] - '0');
    int j = i + k;
    while (j < n) {
      if (s[j] != '?') {
        if (myval == -1)
          myval = (int)(s[j] - '0');
        else if (myval != s[j] - '0') {
          temp = false;
          break;
        }
      }
      j = j + k;
    }
    v[i] = myval;
  }
  if (!temp) return false;
  int one = 0;
  int zero = 0;
  for (int j = 0; j < k; j++) {
    if (v[j] != -1) {
      if (v[j] == 1)
        one++;
      else
        zero++;
    }
  }
  if (one > k / 2 || zero > k / 2) return false;
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if (solve(s, k))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
