#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long int brr[k][2];
  for (long long int i = 0; i < k; i++) {
    for (long long int j = 0; j < 2; j++) {
      brr[i][j] = 0;
    }
  }
  for (long long int i = 0; i < k; i++) {
    for (long long int j = i; j < n; j += k) {
      if (s[j] == '0') {
        brr[i][0]++;
      } else if (s[j] == '1') {
        brr[i][1]++;
      }
    }
  }
  for (long long int i = 0; i < k; i++) {
    if (brr[i][0] != 0 && brr[i][1] != 0) {
      cout << "NO" << '\n';
      return;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '?') {
      if (i - k >= 0 && s[i - k] != '?') {
        s[i] = s[i - k];
      } else if (i + k < n && s[i + k] != '?') {
        s[i] = s[i + k];
      }
    }
  }
  for (long long int i = n - 1; i >= 0; i--) {
    if (s[i] == '?') {
      if (i - k >= 0 && s[i - k] != '?') {
        s[i] = s[i - k];
      } else if (i + k < n && s[i + k] != '?') {
        s[i] = s[i + k];
      }
    }
  }
  long long int cnt0 = 0, cnt1 = 0;
  for (long long int i = 0; i < k; i++) {
    if (s[i] == '1') {
      cnt1++;
    } else if (s[i] == '0') {
      cnt0++;
    }
  }
  if (cnt0 > k / 2 || cnt1 > k / 2) {
    cout << "NO" << '\n';
    return;
  }
  for (long long int i = k; i < n; i++) {
    if (s[i] == '0') {
      cnt0++;
    } else if (s[i] == '1') {
      cnt1++;
    }
    if (s[i - k] == '0') {
      cnt0--;
    } else if (s[i - k] == '1') {
      cnt1--;
    }
    if (cnt0 > k / 2 || cnt1 > k / 2) {
      cout << "NO" << '\n';
      return;
    }
  }
  cout << "YES" << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
