#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return {i, j};
}
struct printer {
  ~printer() { cerr << endl; }
  template <class c>
  printer& operator,(c x) {
    cerr << boolalpha << x;
    return *this;
  }
  printer& operator,(string x) {
    cerr << x;
    return *this;
  }
  template <class c, class d>
  printer& operator,(pair<c, d> x) {
    return *this, "(", x.first, ", ", x.second, ")";
  }
  template <class... d, template <class...> class c>
  printer& operator,(c<d...> x) {
    return *this, range(begin(x), end(x));
  }
  template <class c>
  printer& operator,(rge<c> x) {
    *this, "[";
    for (auto it = x.b; it != x.e; ++it) *this, (it == x.b ? "" : ", "), *it;
    return *this, "]";
  }
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
void solve() {
  int n, K;
  cin >> n >> K;
  string s;
  cin >> s;
  vector<int> opt;
  int z = 0, o = 0;
  for (int i = 0; i < K; i++) {
    int zero = 0, one = 0;
    for (int j = i; j < n; j += K) {
      if (s[j] == '0') zero++;
      if (s[j] == '1') one++;
    }
    if (zero > 0 && one > 0) {
      cout << "NO" << endl;
      return;
    }
    if (zero > 0) {
      z++;
      for (int j = i; j < n; j += K) {
        s[j] = '0';
      }
    } else if (one > 0) {
      o++;
      for (int j = i; j < n; j += K) {
        s[j] = '1';
      }
    }
  }
  if (max(z, o) > K / 2) {
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
