#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000000 + 7;
const long long int N = 1000000 + 6;
int recur_depth = 0;
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(
    Ostream& os, const Cont& v) {
  os << "[";
  for (auto& x : v) {
    os << x << ", ";
  }
  return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
void inp(long long int* arr, long long int n) {
  for (int i = 0; i < n; i++) cin >> arr[i];
}
void inp_mat(long long int* arr, long long int n, long long int m) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      long long int x;
      cin >> x;
      *((arr + i * m) + j) = x;
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char dp[k];
    for (int i = 0; i < k; i++) dp[i] = '?';
    bool bo = true;
    for (int i = 0; i < n; i++) {
      if (s[i] == '?')
        continue;
      else {
        if (dp[i % k] == '?')
          dp[i % k] = s[i];
        else {
          if (dp[i % k] == s[i])
            continue;
          else {
            bo = false;
            break;
          }
        }
      }
    }
    if (bo) {
      int z = 0, o = 0, u = 0;
      for (int i = 0; i < k; i++) {
        if (dp[i] == '0')
          z++;
        else if (dp[i] == '1') {
          o++;
        } else {
          u++;
        }
      }
      int d = abs(o - z);
      u -= d;
      if (u < 0)
        bo = false;
      else {
        if (u % 2) bo = false;
      }
    }
    if (bo)
      cout << "YES\n";
    else {
      cout << "NO\n";
    }
  }
}
