#include <bits/stdc++.h>
using namespace std;
void solution() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int check[k + 1];
  for (int i = 0; i < k + 1; i++) check[i] = -1;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    if (s[i] == '?') continue;
    int index = i % k;
    if (s[i] == '1') {
      if (check[index] == 0) {
        flag = false;
        break;
      }
      check[index] = 1;
    } else if (s[i] == '0') {
      if (check[index] == 1) {
        flag = false;
        break;
      }
      check[index] = 0;
    }
  }
  if (!flag) {
    cout << "NO" << endl;
    return;
  }
  int count0 = 0, count1 = 0;
  for (int num : check) {
    if (num == 1)
      count1++;
    else if (num == 0)
      count0++;
  }
  if (count0 <= k / 2 && count1 <= k / 2) {
    cout << "YES" << endl;
    return;
  }
  cout << "NO" << endl;
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solution();
  }
  return 0;
}
